我正在寻找从以下菜单输出所有页面ID的方法:
<?php wp_list_pages(\'depth=1&exclude=\'3,5,11\')); ?>
只需要顶级页面,因此“深度=1”。感谢您的帮助。
我正在寻找从以下菜单输出所有页面ID的方法:
<?php wp_list_pages(\'depth=1&exclude=\'3,5,11\')); ?>
只需要顶级页面,因此“深度=1”。感谢您的帮助。
wp_list_pages()
用于格式化标记。使用get_pages()
和wp_list_pluck()
:
$pages = get_pages(
array (
\'parent\' => 0, // replaces \'depth\' => 1,
\'exclude\' => \'3,5,11\'
)
);
$ids = wp_list_pluck( $pages, \'ID\' );
$ids
现在保存页面ID数组。你可以用WP_Query
:
$args = array(
\'post_type\' => \'page\',
\'post_parent\' => 0,
\'fields\' => \'ids\',
\'posts_per_page\' => -1,
\'post__not_in\' => array(\'3\',\'5\',\'11\'),
);
$qry = new WP_Query($args);
var_dump($qry->posts);
正如您从var_dump
, $qry->posts
是的数组ID
s$pages = get_pages(
array (
\'parent\' => 0, /* it gives only child of current page id */
\'child_of\' => \'parent or page_ID\' /* Return child of child for page id. */
)
);
$ids = wp_list_pluck( $pages, \'ID\' );
我想在主题的侧栏中列出我当前页面的子页面。但是,我的侧栏(左侧)位于模板中循环之前,如果位于循环之前,则post->ID不会返回任何内容。我的当前代码:<?php wp_list_pages(\'title_li=&child_of=\'.$post->ID); ?> 我读过一些关于调用全局变量来访问它的内容,但到目前为止还没有任何运气。任何帮助都将不胜感激。