I am trying to put together a navigation where the 2nd and 3rd level pages are displaying the same content. I have searched and searched found similar forum questions but none that are exactly the same.
I found this code which is doing what I need on the 3rd level page.
<?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=&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 } ?>
But I want the 2nd level page to also only display it's title and sub pages, so the list would be the same on a level 2 page and a level 3 page. Is there a way to modify this code to target pages with a parent and pages with a grandparent?
On both the 2nd and 3rd level pages the navigation should be:
Second level title name
Subpage of second level 1
subpage of second level 2