WordPress.org

Ready to get started?Download WordPress

Forums

Displaying sibling pages with wp_list_pages. (9 posts)

  1. syrupcore
    Member
    Posted 9 years ago #

    I've been searching and searching. I've seen links to the folding page list plugins at: http://www.webspaceworks.com/wp-plugins/foldpagelist.html Unless I'm grossly misunderstanding the brief docs, I dont think that's what I need.

    I've beaten my site into submission and have all of the child pages displaying in the sidebar of relavant top level pages. When I click one of the child pages, that list of course goes away since the sidebar is set up to display the 'children' of the current page.

    I've seen enough threads here by searching to know that I'm not alone in this quest. I've seen some 'solutions' that suggest setting up multiple templates/sidebars but that seems like the wrong direction. It's like, with wp_list_pages() all of the logic is there, it's just missing a (sibling_of) function.

    Is there a new answer out there that I've just missed? The hack I'm considering (and haven't the faintest idea how to do but I'm learning quick thanks to the codex and this forum) looks something like:

    "if this page is the child of another page, display that other page's children here."

    --or-- (worse)

    "if this page has this ID, display the children of this parent page ID" (yuck)

    Are either of these even possible? At least the first would be automatic. Why are my posts so damn long?

    Thanks so much for any guidance.

    Will

  2. syrupcore
    Member
    Posted 9 years ago #

    http://wordpress.org/support/topic/38264

    seems to be almost there. If....I....could....just....connect...the...dots...

  3. syrupcore
    Member
    Posted 9 years ago #

    I'm so close! Some one, please, help a bruva out.

    <ul class="pages">
    <?php
    $current_page = $post->ID;
    $parent = 1;

    while($parent) {
    $page_query = $wpdb->get_row("SELECT post_name, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
    $parent = $current_page = $page_query->post_parent;
    if(!$parent)
    $parent_name = $page_query->post_name;
    }
    ?>

    <?php global $id; // the page id

    $kids = get_pages("child_of=$id");
    if (count($kids) > 0) {wp_list_pages('child_of=' . $id . '&title_li=&sort_column=menu_order');}
    elseif (count($kids) == 0) {wp_list_pages('child_of=' . $parent . '&title_li=&sort_column=menu_order');}

    ?>
    </ul>

    I've just been hacking and ctrl+Zing and searching and copying and hacking and ctrl+Zing and sea.... It's close! It correctly displays the children of pages with children. on the pages with 0 children, it displays ALL pages and their children. I just want it to display the children of it's parent.

    I tried every variable from the upper area (I'm seriously just guessing and trying again... that's a little closer, guess some more...)

    please help! thankyouthankyouthankyou.

    Will

  4. syrupcore
    Member
    Posted 9 years ago #

    please? pretty please?

  5. kysbruden
    Member
    Posted 8 years ago #

    Hi, I don't know if you figured it out, but I managed to solve it with the this plugin :
    http://brams.dk/public/wp/tbr_article_family.zip

    Here you can check the parent of a page. (You can see an example here: http://www.billnighy.info/filmography/

    The child pages are shown when choosing filmography, and when you click on one of the children, the siblings are displayed.

    Hope this helps you out.

  6. 3stripe
    Member
    Posted 8 years ago #

    Is it possible to list sibling pages, without having to create multiple sidebars? (you have to do this with tbr_article_family.php)

  7. dylan
    Member
    Posted 8 years ago #


    <?php /* Creates a menu for pages beneath the level of the current page */
    if (is_page() and ($notfound != '1')) {
    $current_page = $post->ID;
    while($current_page) {
    $page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
    $current_page = $page_query->post_parent;
    }
    $parent_id = $page_query->ID;
    $parent_title = $page_query->post_title;

    if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_status != 'attachment'")) { ?>

    <div class="sb-pagemenu"><h2><?php echo $parent_title; ?> Subpages</h2>
    <ul>
    <?php wp_list_pages('sort_column=menu_order&title_li=&child_of='. $parent_id); ?>
    </ul>

    <?php if ($parent_id != $post->ID) { ?>
    <a href="<?php echo get_permalink($parent_id); ?>">Back to <?php echo $parent_title; ?></a>
    <?php } ?>
    </div>
    <?php } } ?>

  8. 3stripe
    Member
    Posted 8 years ago #

    Wow thanks Dylan, this is perfecto :)

    One question - if I'm on a parent page, this page is not shown in the list. How could I force it to be shown?

    For example, if you have 'About' with 2 pages below it called 'People' and 'History' - the menu on 'About' lists only these sub pages, and not 'About'. When you go into 'People' or 'History', 'About' then shows up in the list...

  9. 3stripe
    Member
    Posted 8 years ago #

    Ok I worked this out - this is a tweaked version of the above code, which will always include the parent page at the top of the list (even if you are on that page)

    <?php /* Creates a menu for pages beneath the level of the current page */
    if (is_page() and ($notfound != '1')) {
    $current_page = $post->ID;
    while($current_page) {
    $page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
    $current_page = $page_query->post_parent;
    }
    $parent_id = $page_query->ID;
    $parent_title = $page_query->post_title;
    if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_status != 'attachment'")) { ?>
    <ul>
    <?php ?>
    <li><a href="<?php echo get_permalink($parent_id); ?>"><?php echo $parent_title; ?></a></li>
    <?php ?>
    <?php wp_list_pages('sort_column=menu_order&title_li=&child_of='. $parent_id); ?>
    </ul>
    <?php } } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic