更详细的解释。
您首先需要确定您正在查看的页面是否有祖先。如果是子页面,则它有一个祖先;如果是父页面,则它没有祖先。这将决定您:
if (!$post->post_parent):
// will get the subpages of this top level page
$parent = $post->ID;
elseif ($post->ancestors):
// now can get the the top ID of this page
// WordPress puts the IDs DESC, which is why the top level ID is the last one
$parent = end($post->ancestors);
endif;
之后,您只需使用
$parent
变量设置为
child_of
论点因此:
$args_for_step_by_steps = array(
\'post_type\' => \'guides\',
\'sort_column\' => \'menu_order\',
\'title_li\' => __(\'\'),
\'echo\' => 0,
\'child_of\' => $parent
);
因此,只获取子页面的整个功能:
<?php
if (!$post->post_parent):
// will get the subpages of this top level page
$parent = $post->ID;
elseif ($post->ancestors):
// now can get the the top ID of this page
// WordPress puts the IDs DESC, which is why the top level ID is the last one
$parent = end($post->ancestors);
endif;
$args = array(
\'post_type\' => \'guides\',
\'sort_column\' => \'menu_order\',
\'title_li\' => __(\'\'),
\'echo\' => 0,
\'child_of\' => $parent
);
$children = wp_list_pages( $args );
if ($children) :
?>
<nav id="menu-context">
<ul class="menu">
<?php echo $children; ?>
</ul>
</nav>
<?php endif;?>