Support » Fixing WordPress » Sub Navigation in Sidebar

  • Testing Site:

    I only want to display the children of parent in the sidebar when viewing any pages within the parent.

    For example, Oral Health has 10 child pages. Some of those child (Treatment for example) pages have child pages (grandchildren of Oral Health).

    Even if I’m on a grandchild page, I still want to list the only the child pages of the parent.

    This is the code I’m using

    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=1");
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1");
    if ($children) { ?>
    <h2>Oral Health</h2>
    <?php echo $children; ?>
    <?php } ?>

    This code diplays the related grandchild pages when on any grandchild page rather than the child pages.

    (hope that all makes sense…)

  • The topic ‘Sub Navigation in Sidebar’ is closed to new replies.