• PJ

    (@twothirty)


    i’ve been searching for the forums for a while and i’ve not found a post/response to the following situation:

    i’ve created pages in a heirarchy, with subpages. on each page parent AND subpage i want to display a list of the subpages under the parent page when i’m on either the parent or subpage.

    so say the navigation is this:

    HOME
    ABOUT
    – management
    – advisors
    – contact
    COMPANY
    SERVICES
    – service1
    – service2
    – service3

    so, when you’re on ABOUT or any of the children of the about page, you’d see

    ABOUT
    – management
    – advisors
    – contact

    in the sidebar, and similarly the same idea when you’re on SERVICES.

    it seems easy, but for the life of me, i can’t figure it out. if it’s posts and categories instead of pages, doing something with wp_list_cats would probably work, but this is pages.

    ideas? solutions?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I’m *real* new to wp but in my left column php file I found this:
    <?php wp_list_pages(‘sort_column=menu_order’); ?>

    It produces what you see at https://farmbox.com

    Hope this helps.

    this is the way k2 does it ( https://www.binarybonsai.com/k2/ )

    <?php /* Creates a menu for pages beneath the level of the current page */
    if (is_page()) {
    $current_page = $post->ID;
    while($current_page) {
    $page_query = $wpdb->get_row(“SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = ‘$current_page'”);
    $current_page = $page_query->post_parent;
    }
    $parent_id = $page_query->ID;
    $parent_name = $page_query->post_name;

    $test_for_child = $wpdb->get_results(“SELECT * FROM $wpdb->posts WHERE post_parent = ‘$parent_id'”);

    if($test_for_child) { ?>

    <div class=”sb_pagemenu”><h2><?php echo $parent_name; ?> Subpages</h2>

      <?php wp_list_pages(‘sort_column=menu_order&title_li=&child_of=’. $parent_id); ?>

    </div>
    <?php } } ?>

    That is some f$#!&%!?*@! awesome code.

    Lovin’ it.

    This is great but how could I change it so that it only lists pages on the next level down, not every level down. For example I have

    Issues Archive
    – Volume 1
    — Issue 1
    — Story 1
    — Story 2
    — Issue 2
    — Issue 3
    – Volume 2

    So when I’m in ‘Issues Archive’ it only lists ‘Volume 1’ and ‘Volume 2’, and when I’m in ‘Volume 1’ it only lists ‘Issue 1’, ‘Issue 2’ and ‘Issue 3’.

    You could have read the codex finding that this will work fine:

    wp_list_pages('sort_column=post_title&title_li=<h2>Subpages of '. get_the_title() .'</h2>&child_of='. $post->ID'.'&depth=1');

    Didn’t test it, but it should work.

    Thanks for the offer but that doesn’t seem to work. I’m brand new to WP and PHP so finding the appropriate part of the codex has proved difficult.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘displaying subpages dynamically’ is closed to new replies.