在wordpress中创建一个页面层次结构的relativs列表


Create a relativs list of a page hierarchy in wordpress

在wordpress中,我将所有页面按良好的层次结构进行了排序。现在,当我访问某个页面时,我想将父母、亲戚、子女和孙子女列在活动页面上。不是完整的站点页面层次

例如,我的页面层次结构看起来像这个

-Parent1
 nbsp-儿童1-1
 nbsp-儿童1-2
 nbsp nbsp-孙子1-2-1
 nbsp nbsp-孙子女1-2-2
 nbsp-儿童1-3
 nbsp-儿童1-4

-Parent2
 nbsp-儿童2-1
 nbsp-儿童2-2

-Parent3
 nbsp-儿童3-1
 nbsp-儿童3-2
 nbsp nbsp-孙子孙女3-2-1


因此,如果我访问页面">Children2-1",我想要一个仅显示
的列表(菜单(-Parent2
 nbsp-儿童2-1
 nbsp-儿童2-2


如果我访问">孙子3-2-1"列表(菜单(看起来像
-Parent3
 nbsp-儿童3-1
 nbsp-儿童3-2
 nbsp nbsp-孙子孙女3-2-1



我该怎么办?

使用以下工作代码。它会给你想要的结果。

$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>