• 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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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 echo $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 https://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?

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

    Hierarchical Pages widget

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to list subpages in sidebar only when on parent page’ is closed to new replies.