WordPress获取页面ID、名称列表函数:get_page_hierarchy

文 / @WordPress主题

WordPress函数get_page_hierarchy以页面ID为键,名称为值返回页面列表数组。

get_page_hierarchy( WP_Post[] $pages, int $page_id )

函数参数

$pages

数组

页面列表对象,用get_pages()函数获取

$page_id

整数,默认值:0

父页面ID,仅返回指定ID页面的子页面。

函数返回值

Array
(
    [2] => about
    [10] => job
    [15] => contact
    [13] => links
    [8] => service
)

函数使用示例

$all_pages = get_pages( array(
	'post_type'         => 'page',
	'post_status'       => array( 'publish' )
) );
$page_list = get_page_hierarchy($all_pages);

扩展阅读

get_page_hierarchy()函数位于:wp-includes/post.php

相关函数:

  • page_traverse_name()
  • get_pages()
  • get_children()
添加UTHEME为好友
扫码添加UTHEME微信为好友
· 分享WordPress相关技术文章,主题上新与优惠动态早知道。
· 微信端最大WordPress社群,限时免费入群。