Forums

[resolved] find absolute parent of a page hierarchy (4 posts)

  1. pixeline
    Member
    Posted 2 years ago #

    I created a menu using get_pages() and specifying the parent id. This parent id has children and sub-children and sub-subchildren. I need each of these (sub)children to have the parent id displayed .

    The code i made ony works for children, not for sub/ sub-sub children

    $pages = get_pages('child_of=16&parent=16&sort_column=menu_order&sort_order=asc&title_li=&exclude=73');
        foreach($pages as $page) {
    
        <li <?php echo ($post->ID == $page->ID)? 'class="current_page_item"': ''; ?>><a>ID) ?>"><?php echo $page->post_title ?></a>
    
        <?php
    
        }
        ?>

    I'm a bit puzzled on how to achieve that in wordrpress. Any suggestion is welcomed!

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    In your foreach loop $page->post_parent would hold the parent id.

  3. MichaelH
    Volunteer
    Posted 2 years ago #

    See you've also ask the same question at http://stackoverflow.com/questions/1566388/wordpress-template-tags-getpage and given more explanation.

    So look at the get_post_ancestors() function.

  4. pixeline
    Member
    Posted 2 years ago #

    Excellent, looks like it should do the trick !

Topic Closed

This topic has been closed to new replies.

About this Topic