So I have been searching online for something that I think is simple to achieve and I am most likely over thinking it. I have found many related articles on the matter but can't seem to get it to apply to my scenario. I have a sidebar menu on my site that displays a tier of sub-pages. So if you click on "Services" the sidebar shows
- Service 1
- Service 2
- Service 3
- Service 4
- Service 5
This is perfect, as these are my 5 sub-pages underneath "Services". Now "Service 1, 2 & 3" have anywhere from 5-15 sub-pages under them. What I want to achieve is if you click on "Service 1" in the sidebar and the page loads the sidebar will adjust to show:
- Service 1 -- sub-page 1 -- sub-page 2 -- sub-page 3
- Service 2
- Service 3
- Service 4
- Service 5
So on the 3rd tier of pages I still want the sidebar to display the main sub-services links but if you are on a sub-service page that has its own sub-pages I would like it to display those sub-pages as well as the original main service sub-pages.
Currently I have only been able to get this show like this:
Click on "Service 1", sidebar menu reflects: - Service 1 -- sub-page 1 -- sub-page 2 -- sub-page 3 - Service 2 - Service 3 - Service 4 - Service 5
Which is good, but then if I click on one of those "sub-pages" the menu updates to only show the sub-pages of that service and not the menu structure that was there before.
Sorry for the long post. I have tried this link using a custom walker: http://wordpress.mfields.org/2010/selective-page-hierarchy-for-wp_list_pages/ I have also tried:
<ul class="sidebar_menu">
<?php wp_list_pages( array('title_li'=>'','include'=>get_post_top_ancestor_id()) ); ?>
<?php wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>get_post_top_ancestor_id()) ); ?>
</ul>
No luck though. Thanks for any help! EDIT: Also have tried the following (which works up until the 3rd tier is reached, then it drops the "2nd" tier of sub-pages.)
<?php
$ancestor_id=$post->post_parent;
$descendants = get_pages(array('child_of' => $ancestor_id));
$incl = "";
foreach ($descendants as $page) {
if (($page->post_parent == $ancestor_id) ||
($page->post_parent == $post->post_parent) ||
($page->post_parent == $post->ID))
{
$incl .= $page->ID . ",";
}
}
?>
<ul>
<?php wp_list_pages(array(
"child_of" => $ancestor_id,
"include" => $incl,
"link_before" => "",
"title_li" => "",
"sort_column" => "menu_order"
));
?>
</ul>
$post
to retrieve the current page object. Then, just retrieve the parent or child pages of the current page object as necessary.global $post;
, all parent pages of the current page, along with all child pages of the current page.