• I’m working on a sidebar navigation menu. I have a three level hierarchy (parent -> child -> grandchild) and I am trying to do the following:

    • If the current page is a parent page, only show all parent pages.
    • If the current page is a child page, only show all child pages for that parent, and all parent pages.
    • And if the current page is a grandchild page, show all grandchildren for this child page, show all child pages for this parent, and show all parent pages.

    This is a good case for wp_list_pages but I cannot figure out the how to get this done with PHP. Here is a link to my test site that shows the page behavior the way I would like it to work.

    Any help is appreciated of course.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Look at the ancestors array when the $myposts object is dumped

    <?php
    $node = (int) 234; // or whatever id you are working with
    $mypost = get_post($node);
    echo "<pre>"; print_r($mypost); echo "</pre>";
    ?>
    Thread Starter glenngeiger

    (@glenngeiger)

    Thank you for the $mypost code. I see that the ancestors array returns the ID’s of the parent pages (if any). I also see post_parent returns the ID of the parent above the current page.

    Can anyone assist with the PHP needed to hide/show the child UL if the current page has child pages, without removing the parent pages?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show Higher Level Pages with wp_list_pages’ is closed to new replies.