• Hi there,

    I’m trying to list the parents siblings of a page.

    I’ve just spent way too long trying to find a way to do this.
    I thought I’d find the pages parents parent ID, then do something like this:

    `wp_list_pages(‘title_li=&child_of=’.$secondParentsID);

    However I continue to fail…
    Any help would be greatly appreciated.

    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • this might work:

    <?php if( is_page() && $post->post_parent ) :
    wp_list_pages('title_li=&parent='.$post->post_parent);
    endif; ?>

    the conditional helps to avoid to show the page list in the wrong situations;
    and the ‘parent’ parameter will show only the direct child level
    (not documented in the codex chapter for ‘wp_list_pages()’ , but seems to work analogous to ‘get_pages()’ )

    alternatively, try:

    <?php if( is_page() && $post->post_parent ) :
    wp_list_pages('title_li=&child_of='.$post->post_parent.'&depth=1');
    endif; ?>

    http://codex.wordpress.org/Function_Reference/wp_list_pages

    Thread Starter HarleyB

    (@harleyb)

    Unfortunately, that only lists the current pages siblings – I’m looking to list the parents siblings.
    Thanks nonetheless..!

    I want to do the same thing. It seems there’s no built-in WP function for listing a specific page’s siblings — only children.

    just have to go up one level:

    <?php if( is_page() && get_post($post->post_parent)->post_parent ) :
    wp_list_pages('title_li=&parent='.get_post($post->post_parent)->post_parent);
    endif; ?>

    Thanks, alchymyth, for showing us how to traverse up the tree of posts/pages. Your solution is more elegant than another one I just found:

    http://stackoverflow.com/questions/4314918/wordpress-wp-list-pages-list-parent-page-siblings/4316179#4316179

    Is there a way to include both the parent page’s siblings and the current page’s siblings at the same time? Maybe even going one step deeper and showing current page’s children..

    This is to create a tree-like navigation, like this:

    |- Parent sibling #1
    |- Parent
    |– Current page sibling #1
    |– Current page
    |— Child of current page #1
    |— Child of current page #2
    |– Current page sibling #2
    |- Parent sibling #2

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘List parents siblings with wp_list_pages (page)’ is closed to new replies.