[resolved] Excluding Child Pages on sidebar (3 posts)

  1. jtancil
    Posted 3 years ago #

    : Hi,
    I am using WordPress to power a site which has a subnavigation menu on the sidebar. The site has many pages, child pages and grandchildren.

    Using the code below, I can show the titles of all child pages and the titles of all their grandchildren.

    However, I only want to display the title of the current child page and its grandchildren; I don't want to show links to other child pages nor their grandchildren.

    For instance, on this page (http://www.sitesofconscience.org/sites/accredited-members/gulag-museum) I ONLY want to show the current page title and its grandchildren, so everything from "Gulag Museum" to "Dialogues for Democracy".

    "Constitution Hill" and the links underneath it are another child page and its grandchildren; I don't want those links to appear.

    Is there any way to do this, perhaps by modifying the code I have a bit? Or, is there a conditional statement I could use? I have many pages on the site and I'd rather not use menus.

    Thanks for any hints or suggestions.

    	if (in_array($post->post_parent, array(7,217,246,47))) {
    		//if parent is sites page, post own children
    		$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&sort_column=menu_order");
    	} else {
    		//otherwise, post parent's children
    		$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&sort_column=menu_order");
    	if ($children) echo "<ul>" . $children . "</ul>";?>
  2. Jonathan Dingman
    Posted 3 years ago #

    This solution would probably work pretty well for your needs.


  3. jtancil
    Posted 3 years ago #

    Hi Jonathan,
    Thank you for the suggestion, it does look good.

    The code I have actually also works, I simply needed to add the ID of the page I wanted to exclude child pages on to that first if statement.

    Thanks again,

Topic Closed

This topic has been closed to new replies.

About this Topic