• Hi, I have searched around but I can’t find exactly what I’m looking for. When on a certain page I want to list in the sidebar the page you are on and the children of that page. And the same to be listed when on the child page.

    Is this possible? I would appreciate anyones help.

    WordPress 2.7

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Rob Cubbon

    (@robcub)

    I’ve found putting this code in sidebar lists child pages if there are any of the parent plus lists them if you are on one of the child pages:

    <?php
    global $wp_query;
    if( empty($wp_query->post->post_parent) ) {
    $parent = $wp_query->post->ID;
    } else {
    $parent = $wp_query->post->post_parent;
    } ?>
    <?php if(wp_list_pages("title_li=&child_of=$parent&echo=0" )): ?>
    <div id="submenu">
    <ul>
    <?php wp_list_pages("title_li=&child_of=$parent" ); ?>
    </ul>
    </div>
    <?php endif; ?>

    Found it here: https://www.blogherald.com/2007/07/26/wordpress-dynamic-sub-page-navigation/

    mo_m

    (@mo_m)

    What will happen if there are submenus of submenu?
    For example:

    main
       |----subposition
       |----subposition
            |-------- sub-subposition
            |-------- sub-subposition
       |----subposition

    When you enter the page “sub-subposition” variable $wp_query->post->post_parent gives you ID of subposition, not main… Am I right?

    Thread Starter Rob Cubbon

    (@robcub)

    I think you are, mO_m, the guy says on the page I linked to:

    I didn’t spend too much time doing research on this, but as far as I can tell, this only works 2 levels deep (top-level and 2nd level). If you have 3 levels of sub-pages, this won’t work (or at least won’t work like it’s supposed to).

    I just found by trial and error something that was close to what I was looking for – I’m a PHP noob.

    It would be good to know how to display a page and the sub-pages, and sub-sub-pages of it when you are on either that page or one of it’s sub-pages.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘List page and children of current page with links’ is closed to new replies.