Firstly, apologies for the terminology used here, I will try to be as descriptive as possible.
I am trying to create a menu system that will achieve the following:
- List top level pages as one menu (level 1)
- When on a top level page, list the child pages in a separate menu (level 2)
- When on a child page, list the child pages of that child as a further separate menu (level 3)
From the Codex this creates the menu which happily lists 3 levels of pages:
<?php if(!$post->post_parent){
// will display the subpages of this top level page
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
}
else{
// diplays only the subpages of parent level
//$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
if($post->ancestors)
{
// now you can get the the top ID of this page
// wp is putting the ids DESC, thats why the top level ID is the last one
$ancestors = end($post->ancestors);
$children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
// you will always get the whole subpages list
}
}
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
This is fine, but all page listings are in a single list, in one place.
I need to split this out so I can just grab the child pages, and display that menu in a <div>
in one part of my page, then i need to grab the third level pages, and display those in another part of my page, in a separate <div>.
Any clues how to do this?
Many thanks