In wordpress I have sorted all pages in a nice hierarchy. Now I want to list the parents, relativs, children and grandchildren to the active page when I visit a page. Not the full site page hierarchy
For exemple my page hierarchy looks like this
-Parent1
-Children1-1
-Children1-2
-grandchildren1-2-1
-grandchildren1-2-2
-Children1-3
-Children1-4
-Parent2
-Children2-1
-Children2-2
-Parent3
-Children3-1
-Children3-2
-grandchildren3-2-1
So if i visit page "Children2-1" i want a list(menu) thats shows only
-Parent2
-Children2-1
-Children2-2
And if I visit "grandchildren3-2-1" the list(menu) look like
-Parent3
-Children3-1
-Children3-2
-grandchildren3-2-1
How can I manage this? ?
Use below working code. It will give you result as you want.
$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>