WordPress.org

Ready to get started?Download WordPress

Forums

Only Display Immediate Children (6 posts)

  1. inspiredrichard
    Member
    Posted 3 years ago #

    Hi there

    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:

    <ul class="sidebar">
    <?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?

    Cheers

    Richard

    [Please post code snippets between backticks or use the code button.]

  2. inspiredrichard
    Member
    Posted 3 years ago #

    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?

    Cheers

    :-)

  3. cubecolour
    ɹoʇɐɹǝpoɯ
    Posted 3 years ago #

    You should be able to use the sub pages widget plugin for this http://wordpress.org/extend/plugins/subpages-widget/

  4. Ryan Paul
    Member
    Posted 3 years ago #

    Couldn't you just add '&depth=2' ?

  5. inspiredrichard
    Member
    Posted 3 years ago #

    Hi othellobloke

    I tried that and it made no difference :-/

    thanks anyway :-)

  6. learncomputer
    Member
    Posted 2 years 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.

Topic Closed

This topic has been closed to new replies.

About this Topic