WordPress.org

Ready to get started?Download WordPress

Forums

Navigation to show sub levels if in parent (1 post)

  1. candell
    Member
    Posted 2 years ago #

    I almost have what I need but am struggling with the final part. Here's what I need.

    My website has three levels deep

    Page 1
    Sub page 1
    Sub page 2
    Page 2
    Page 3
    Sub page 1
    Sub page 2
    Sub sub page 1
    Sub sub page 2
    Page 4

    So, if the user is on a top level page they see other top levels and the child pages i.e. page 1, they see

    Page 1
    Sub page 1
    Sub page 2
    Page 2
    Page 3
    Page 4

    If they are page 3 sub sub page 1;

    Page 1
    Page 2
    Page 3
    Sub page 1
    Sub page 2
    Sub sub page 1
    Sub sub page 2
    Page 4

    This is working on all levels apart from sub sub pages which only sees the top level pages. It should see the final example above but it is showing

    Page 1
    Page 2
    Page 3
    Page 4

    Here's the code

    <ul>
    <?php
    $Pages = wp_list_pages('title_li=&echo=0&depth=1');
    $InnerPages = wp_list_pages('child_of='.($post->post_parent != false ? $post->post_parent : $post->ID).'&title_li=&echo=0');
    $Title = ($post->post_parent != false) ? trim(get_the_title($post->post_parent)) : trim(wp_title('', false));
    if($Title != '')
    $Pages      = str_replace($Title.'</a></li>',
    								$Title.'</a>'.
    								'<ul>'.$InnerPages.'</ul></li>',
    								$Pages);
    echo $Pages;
    unset($Pages, $InnerPages);
    ?>
    </ul>

    Can anyone help?

Topic Closed

This topic has been closed to new replies.

About this Topic