Only show child pages when page has them
-
I’m trying to get a sub navigation established on my website.
I have 4 pages contained in one main parent page called About. The structure looks like this;
About
— Mission
— Committees
— PeopleI have can get it to display the above setup, but the Committees page has 4 children of its own, and I only want those children to display when someone is on the committee page OR any of the committee’s child pages.
So far, this is my code, which displays everything …. regardless of which page you are on in the main parent page.
<?php if(!$post->post_parent){ $children = wp_list_pages("title_li=&depth=1&child_of=".$post->ID."&echo=0"); }else{ if($post->ancestors) { $ancestors = end($post->ancestors); $children = wp_list_pages("title_li=&depth=1&child_of=".$ancestors."&echo=0"); } } if ($children) { ?> <ul> <?php echo $children; ?></ul> <?php } ?>
Its doing it right by showing all the children under the main parent, but its showing the grand children when it should only show them on the child they belong to.
If that make sense.
So when I’m on any of the committees pages (including committees), it should look like this
About
— Mission
— Committees
—- Committees 1
—- Committees 2
— PeopleAnd when I’m on the Mission page, it should look like this (below) since Mission has no children.
About
— Mission
— Committees
— PeopleAny help would be appreciated!
- The topic ‘Only show child pages when page has them’ is closed to new replies.