Support » Fixing WordPress » Sidebar Link Listing Issues (Parent and Child pages)

  • I have searched the forums and documentation and cannot find a solution to exactly my issue. Hopefully someone knows the answer. I am trying to do the following.

    In my sidebar.php file I want to list provide a list of links to children of the parent page that is being viewed BUT ONLY if the parent has children. This I can do with the following syntax:

    <?php if(wp_list_pages("child_of=".$post->ID."&echo=0")) { ?>
    <!-- List of Pages in this Section -->
    <h3>Pages Within This Section:</h3>
    <ul>
    <?php wp_list_pages("title_li=&child_of=".$post->ID."&sort_column=menu_order");?>
    </ul>
    <?php } ?>

    However when I go to one of the child pages the menu is no longer displayed and I would like it to be. I know the syntax above is filtering out the display because the child page does not have a child, but how can I modify it so that it knows to display the menu if there is a child?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter berchman

    (@berchman)

    I found the exact solution to my WP ills here:

    http://wordpress.org/support/topic/57985?replies=6

    berchman,

    I want the same thing. Unfortunately, I’m a bit of a WordPress newb. I’ve been pretty good at creating new Page Templates and such but this one has me for a bit of a loop. The thread you linked to is closed so I can’t ask there but could you please explain what you did? What code did you put into your sidebar.php? Your help would be greatly appreciated.

    Houston Graham

    This is a great start on what I want. Now what I’d like is to NOT display the siblings of the parent page. for example, if I have:

    Nuts
    Vegetables
    Fruit

    and Fruit has child pages of

    Apples
    oranges
    kiwi

    What I currently get (using the menu from the updated version of the theme mentioned above) is:

    Nuts
    Vegetables
    Fruit
    apples
    oranges
    kiwi

    And I assume that if Nuts and Vegetables have child pages, they display as well (on all pages)

    I find it SO hard to believe that after all these years, no one involved in changing WordPress has thought of a way to display the child pages of a parent in the sidebar (while on parent OR child pages) without also displaying every other page in the site.

    Wouldn’t this be a basic necessity for the average site?

    I had a script that worked for v2.1 but it no longer works.

    Even my script (which does work) displays the sibling pages of the parent… how does one turn those off?

    This does the same thing (use in sidebar) to list child pages:

    <ul>
    <?php 
    
    //CHECK TO SEE IF PAGE IS A CHILD PAGE OR HAS CHILDREN
    	if($post->post_parent) {
    	// page is a child
    	wp_list_pages('depth=2&sort_column=menu_order&title_li=&child_of='.$post->post_parent);
    
    	}
    //page is a parent
    	elseif (wp_list_pages("child_of=".$post->ID."&echo=0")) {
    	wp_list_pages('depth=1&sort_column=menu_order&title_li=&child_of='.$post->ID);
    	}
    ?>
    </ul>

    but still has the issue of displaying the siblings (and their child pages) which is a mess.

    If any one knows how to exclude siblings of the parent ($post->ID) that would be SO awesome!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Sidebar Link Listing Issues (Parent and Child pages)’ is closed to new replies.