• Hi, I am trying to write a navigation scheme for a page that displays a list of not the parent, and nor the children of the current page, but just it’s brothers and sisters. So, if my structure is

    1 – Cars
    * Ford
    * Honda
    * Chevy
    2 – Planes
    * Boing
    * Airbus

    and I was on the Honda page, I would want my list to display just Ford, Honda, and Chevy. I think the best way to do this is something like:
    [code]wp_list_pages('child_of=' . $pageParent);[/code]

    but I have googled and searched the codex and am unable to figure out how to get from WordPress the ID number of the parent of the page.

    The closest I found was this:
    [code]
    $object = $wp_query->get_queried_object();
    $parent_id = $object->post_parent;
    [/code]

    But it does not work, always returning a $parent_id of 0, even though that code is in the loop. I think I am misunderstanding the way WPQuery works.

    Any help would be appreciated. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey Gedtech, try this out:

    <?php
    
    if($post->post_parent) { // page is a child
    
    wp_list_pages('sort_column=menu_order&title_li= &child_of='.$post->post_parent);
    
    }
    
    elseif(wp_list_pages("child_of=".$post->ID."&echo=0")) { // page has children
    
    wp_list_pages('sort_column=menu_order&title_li= &child_of='.$post->ID);
    }
    ?>

    Oh nifty Just what I was looking for.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get the parent id of a page’ is closed to new replies.