Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 134735

Sarah_Frantz on "Only show child pages when page has them"

$
0
0

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
-- People

I 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
-- People

And when I'm on the Mission page, it should look like this (below) since Mission has no children.

About
-- Mission
-- Committees
-- People

Any help would be appreciated!


Viewing all articles
Browse latest Browse all 134735

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>