I’m trying to have a navigation menu for the sidebar of my site that shows only one level of child pages and still keep the parent/grandparent pages when on the child/grandchild pages.
Here’s the functioning example of what I have so far.
1) You’ll see that when you are on the About page, you don’t see the children/grandchildren of the Stylist Bios page. On the Stylist Bios, you’ll see the children (i.e. Tamara Dahill & Allison Carroll) and the grandchildren (i.e. Allison Carroll’s Fun Facts). I only want to show each stylist’s name (the child pages) and not the Fun Facts page (grandchild page). I haven’t figured using &depth= to work.
2) When you are on Allison Carroll’s page (child), the upper level pages disappear (About, Accolades, Products We Use, Salon Policy). I can’t figure out how to make these stay.
3) When on a child/grandchild page with no lower level pages, the sidebar disappears completely. Not sure how to stop this from happening.
Here’s the code:
<?php
/* if the current pages has a parent, i.e. we are on a subpage */
if($post->post_parent){
$children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0"); // list the parent page
$children .= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); // append the list of children pages to the same $children variable
}
/* else if the current page does not have a parent, i.e. this is a top level page */
else {
$children = wp_list_pages("title_li=&include=".$post->ID."&echo=0");
$children .= wp_list_pages("title_li=&child_of=".$post->ID."&echo=0"); // form a list of the children of the current page
}
/* if we ended up with any pages from the queries above */
if ($children) { ?>
<ul class="submenu">
<?php echo $children; /*print list of pages*/ ?>
</ul>
<?php } ?>
Any help would be greatly appreciated! Please let me know if I can be any more clear in what I am talking about.