Support » Fixing WordPress » Only Display Immediate Children
6 years ago
I need to add a sidebar for navigation for only the immediate children of a page, not its grandchildren.
I found a piece of code which displays children and grandchildren:
<?php wp_list_pages('child_of='.get_the_ID().'&title_li=<div class="sideTitle">'.__('Next Steps').'</div>');
Any ideas on how to make it only display immediate children?
[Please post code snippets between backticks or use the code button.]
Actually I just realised that I also need to show the siblings of the page I am on.
any chance of a hand with that too?
You should be able to use the sub pages widget plugin for this http://wordpress.org/extend/plugins/subpages-widget/
Couldn’t you just add ‘&depth=2’ ?
I tried that and it made no difference :-/
thanks anyway 🙂
5 years, 2 months ago
This will give you the list of immediate children of a given page.
$children = get_pages(array(
'child_of' => $your_page_ID,
'parent' => $your_page_ID,
'sort_order' => 'ASC',
'sort_column' => 'menu_order'
Also see http://codex.wordpress.org/Template_Tags/wp_list_pages#List_parent_Page_and_all_descendant_Pages for additional examples.