Excluding Child Pages on sidebar
-
: 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>";?>
-
This solution would probably work pretty well for your needs.
http://www.jonathan.vc/show-only-children-pages-on-parent-page.html
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,
Jeff
- The topic ‘Excluding Child Pages on sidebar’ is closed to new replies.