Excluding Child Pages from sidebar navigation

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 all child pages and all their grandchildren.

However, on certain pages, 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?

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>";?>

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


What version of wordpress are you using?

You should be able to do what you want, I do something similar on a couple of sites.

rjunkAuthor Commented:
I am running 3.2.1.  If feasible, I'd rather do this with a simple statement (a conditional one?) in the template file for these pages rather than using menus.  

I am bashing my head here, just trying to get those other child pages to NOT show.  This must be doable, but I am a php newbie/nitwit.

Thank you!
can you post more of the code surrounding that snippet?

What I would probably do if you want it that way is to make a custom variable on your page that you can read in your php and from that determine whether to display that info or not. For example

Custom Variable: display-child-menu-list
value: true

if it isn't set to true or it isn't set at all, ignore that section of code. If it is set to true display the list.

At first glance the code you have there looks like it should do what you want, it makes me think there might be some more code above it or below it that is activating to display the content you don't want...
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

rjunkAuthor Commented:
Thanks so much for the continued help.  If the current code is resolvable, that would be better, I think.  And, once upon a time, it  was working, so I wonder if your suspicion is correct.  I attached the entire template file as well as the header file.  Please let me know if I can offer anything else (a steak dinner?)

Thank you!
does accreddited sites have a post/page id of 7, 217, 246, or 47?

rjunkAuthor Commented:
Hi, no, it does not have an ID that matches any of those numbers.
ok, because accredited sites is the parent of Gulag Museum, so since it's ID is not in that list, it will go to the else statement and display all the pages that are a child of "Accredited  Sites", add the id of accredited sites to the array in the if statement and it should fix that page. You will need to update that array to include any page you want to work that way.

if (in_array($post->post_parent, array(7,217,246,47,add accredited site id here))) {

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rjunkAuthor Commented:
WooHoo! That did it. Oh man, I feel terribly stupid, but also eternally grateful. Many shamefaced, but sincere thank yous. Thank you!
rjunkAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.