WordPress.org

Ready to get started?Download WordPress

Forums

How to list subpages in sidebar only when on parent page (4 posts)

  1. andersronnau
    Member
    Posted 5 years ago #

    Hi All

    To keep my sidebar list of pages as compact as possible, I would like to show the subpages/children ONLY for the parent page that I am already on. And of course while on any of the children pages of that parent.

    Best - Anders.

  2. scripty
    Member
    Posted 5 years ago #

  3. cateradebaugh
    Member
    Posted 5 years ago #

    Hi Scripty - I found your link and copied and pasted this into the sidebar of my site:

      <?php wp_list_pages('title_li=<h2>MAIN NAV</h2>&depth=1' ); ?>

    <?php
    if ($post->post_parent == 0) {
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    $parentpage = $wpdb->get_row("SELECT ID, post_title, post_name FROM $wpdb->posts WHERE ID = '".$post->ID."'");
    }
    if ($post->post_parent != 0) {
    $next_post_parent = $post->post_parent;
    while ($next_post_parent != 0) {
    $children = wp_list_pages("title_li=&child_of=".$next_post_parent."&echo=0");
    $parentpage = $wpdb->get_row("SELECT ID, post_title, post_parent, post_name FROM $wpdb->posts WHERE ID = '".$next_post_parent."'");
    $next_post_parent = $parentpage->post_parent;
    }
    }
    ?>
    <?php if ($children) { ?>

    <?php } ?>

    But nothing happens. What I'd like is to have the same set up you have - I'm using the simpleX theme, and my link is http://www.transformationacceleration.com --- I know that WordPress is supposed to be simple, but I don't understand what I'm doing at all.
    I would be very grateful for any help you or anyone else could give me about how to make the parent-child page list show up in my sidebar. And my other question is, should that happen, will I automatically be able to go to the admin page and put in content?

  4. wlindley
    Member
    Posted 4 years ago #

    This might be just what you are looking for. Replace the standard Pages widget with:

    Hierarchical Pages widget

Topic Closed

This topic has been closed to new replies.

About this Topic