WordPress获取页面ID、名称列表函数:get_page_hierarchy
WordPress函数get_page_hierarchy以页面ID为键,名称为值返回页面列表数组。 get_page_hierarchy( WP_Post[] $pages, int $page_id ) 函数参数$pages 数组 页面列表对象,用get_pages()函数获取 $page_id 整数,默认值:0 …
WordPress函数get_page_hierarchy以页面ID为键,名称为值返回页面列表数组。 get_page_hierarchy( WP_Post[] $pages, int $page_id ) 函数参数$pages 数组 页面列表对象,用get_pages()函数获取 $page_id 整数,默认值:0 …
WordPress函数get_page_children用于获取子页面对象 get_page_children( int $page_id, array $pages ) 函数参数$page_id 整数 父页面ID $pages 数组 页面列表对象,用get_pages()函数获取 函数返回值Array ( [0] => WP_Post Object ( [ID] => 15 [post_author] => 1 [post_date] => 2020-11-27 16:37:42 [post_date_gmt] => 2020-11-27 08:37:42 [post_content] => [post_title] => 联系我们 [post_excerpt] => [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => contact [to_ping] => [pinged] => [post_modified] => 2021-02-22 11:00:05 [post_modified_gmt] => 2021-02-22 03:00:05 [post_content_filtered] => [post_parent] => 2 [guid] => https://www.beizigen.com/?page_id=15 [menu_order] => 0 [post_type] => page [post_mime_type] => [comment_count] => 0 [filter] => raw ) ) 函数使用示例$all_pages = get_pages( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'pending' ) ) ); $inherited = get_page_children(2, $all_pages); 扩展阅读get_page_children()函数位于:wp-includes/post.php …
WordPress函数get_page_by_title根据页面标题获取页面对象,如果有相同名称标题的页面,则返回最早发布的页面。 get_page_by_title( string $page_title, string $output = OBJECT, string|array $post_type = 'page' ) 函数参数$page_title …
WordPress函数get_page_by_path根据页面路径获取页面对象 get_page_by_path( string $page_path, string $output = OBJECT, string|array $post_type = 'page' ) 函数参数$page_path 字符串 页面的路径,不包含域名部份,例如: /about/contact $output 字符串 返回数据的类型,可用值如下: …
WordPress函数get_page_link用于获取指定页面的链接 get_page_link( int|WP_Post $post = false, bool $leavename = false, bool $sample = false ) 函数参数$post 整数或WP_Post 页面ID $leavename 布尔值,默认值:false 是否返回固定链接设置,当为true时返回结果如下: …
WordPress函数get_ancestors可以用于获取分类的祖先ID,或页面的祖先ID,包括所有的上级。 get_ancestors( int $object_id, string $object_type = '', string $resource_type = '' ) 函数参数$object_id 整数 对象ID $object_type 字符串 对象类型,可用值:page、post、category或其他分类法名称 …
WordPress函数get_all_page_ids用于获取所有页面的ID,以数组的形式返回结果,该函数没有任何参数。 get_all_page_ids() 函数使用示例以下示例代码输出所有页面的链接列表: $page_ids = get_all_page_ids(); echo '<h3>页面:</h3><ul>'; foreach($page_ids as $page) { echo '<li><a href="' . get_permalink($page) . '">' . get_the_title($page) . '</a></li>'; } echo '</ul>'; 扩展阅读get_all_page_ids()函数位于:wp-includes/post.php …
WordPress函数wp_publish_post用于修改文章的状态为publish wp_publish_post( int|WP_Post $post ) 函数参数$post 整数 要修改的文章ID 扩展阅读wp_publish_post()函数位于:wp-includes/post.php …
WordPress函数wp_update_post用于更新现有的文章 wp_update_post( array|object $postarr = array(), bool $wp_error = false, bool $fire_after_hooks = true ) 函数参数$postarr 数组 可用值参考wp_insert_post()函数的$postarr参数 $wp_error 布尔值,默认值:false 是否返回错误信息 $fire_after_hooks 布尔值,默认值:true …
WordPress函数wp_insert_post用于插入一篇新的文章。 wp_insert_post( array $postarr, bool $wp_error = false, bool $fire_after_hooks = true ) 函数参数$postarr 数组 ID:文章的ID,如果传递0以外的值,则更新相应ID的文章而不是插入新的文章; post_author:作者的ID,默认为当前作者; post_date:发表时间,格式为Y-m-d H:i:s,默认为当前时间; post_date_gmt:发表文章的格林时间,与国内时区相差8小时; post_content:文章内容; post_content_filtered:文章内容过滤; post_title:文章标题; post_excerpt:文章摘要; post_status:文章状态,默认值:draft post_type:文章类型,默认值:post comment_status:是否允许评论,可用值:open或closed,默认取wp_options表中default_comment_status的值,即后台讨论设置中“允许他人在新文章上发表评论”选项; ping_status:是否允许其他博客发送链接通知,可用值:open或closed,默认取wp_options表中default_ping_status的值,即后台讨论设置中“允许其他博客发送链接通知(pingback和trackback)到新文章”选项; post_password:访问密码,默认为空; post_name:文章别名; to_ping:使用空格或回车分隔要ping的URL列表; pinged:空格或回车分隔已ping的url列表; post_modified:文章的修改时间,格式为Y-m-d H:i:s,默认为当前时间; post_modified_gmt:修改文章的格林时间; post_parent:父级ID; menu_order:文章的显示顺序; post_mime_type:MIME类型,适用于插入附件时; guid:文章链接,当设置固定链接后为伪静态格式,默认为动态链接; post_category:数组,文章分类的ID; tags_input:数组,标签名称、别名或ID; tax_input:数组,自定义分类法名称; meta_input:数组,post meta的键值对; $wp_error …