• 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 1 replies (of 1 total)
  • Did you ever come up with a solution for this? I’m looking for something similar, and haven’t had any luck so far.

Viewing 1 replies (of 1 total)
  • The topic ‘Only show child pages when page has them’ is closed to new replies.