[resolved] list the top-most parent page of a sub page (3 posts)

  1. shagdirty
    Posted 5 years ago #

    howdy. I'm trying to list (or get the name of really) the top-most parent page of any sub page, be it child, grandchild, great grandchild etc. I've done some digging and found only a "Simple Section Nav" plugin. I'm trying to avoid the plugin route and I wasn't able to gut the code I needed from it. (I'm not a super savvy developer).

    So basically I'm thinking of this like sections. I've got an About "section" that has child pages and grandchildren as well and regardless of how deep you are in the About "Section" (on a child or grandchild page of About), I want to get the name of the top-most parent. In this case, the "About" page. I found plenty of solutions for just listing the parent but haven't found any solid ones for top-most parent. Any help would be greatly appreciated

    thanks, Shag

  2. DigitalSquid
    Posted 5 years ago #

    Try this:

    $parents = get_post_ancestors( $post );
    echo get_the_title( end($parents) );

  3. shagdirty
    Posted 5 years ago #

    man, THANKS! that is exactly what I needed. worked like a charm.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.