在wordpress中,我已经在一个很好的层次结构中对所有页面进行了排序。现在,当我访问一个页面时,我想把父母、亲戚、孩子和孙子列在活动页面上。不是完整的站点页面层次结构。
例如,我的页面层次结构如下所示
-Parent1
_-Children1-1_
_-Children1-2_
_-grandchildren1-2-1_
_-grandchildren1-2-2_
儿童1-3
儿童1-4
-Parent2
儿童2-1
儿童2-2
-Parent3
儿童3-1
儿童3-2
_-grandchildren3-2-1_
因此,如果我访问页面“2-1”,我想要一个仅显示的列表(菜单)。
-Parent2
儿童2-1
儿童2-2
如果我访问"grandchildren3-2-1“,列表(菜单)看起来就像
-Parent3
儿童3-1
儿童3-2
_-grandchildren3-2-1_
我怎么处理这个??
发布于 2015-01-19 12:58:00
使用下面的工作代码。它会给你你想要的结果。
$parrent_pgid=$post->post_parent;
$current_pgid=$post->ID;
get_page_template_slug( $current_pgid );
?>
<div class="left_sidebar" id="pg_<?php echo $current_pgid;?>">
<?php
if ($post->post_parent) {
$ancestors=get_post_ancestors($post->ID);
$root=count($ancestors)-1;
$parent = $ancestors[$root];
} else {
$parent = $post->ID;
}
$children = wp_list_pages("sort_column=post_title&title_li=&child_of=". $parent ."&echo=0");
if ($children) { ?>
<ul id="subnav">
<?php echo $children; ?>
</ul>
<?php } ?>
</div>
https://stackoverflow.com/questions/28024527
复制相似问题