0

For example, if this were my page structure:

Food
    Vegetables
    Dairy
    Fruits
        Apples
        Bananas
        Kiwis
        Oranges
Sports
    Hockey
    Baseball
    Football
Entertainment
    Movies
    TV
    Podcasts

... and I was on the Oranges page, it would display this:

Food
    Vegetables
    Dairy
    Fruits
        Apples
        Bananas
        Kiwis
        > Oranges
Sports
Entertainment

I'm attempting to use wp_list_pages() and its child_of option, but it appears to only accept an integer rather than array so I can't just pass what is returned of get_ancestors($post->ID, 'page')

1

You can get top levels page id with following function

function find_top_level_id( $post_id ) {
   $ancestors = get_post_ancestors( $post_id );

    if ( $ancestors ) {
        return end( $ancestors );
    } else {
        return $post_id;
    }
}

You can use the returned value with wp_list_pages()

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.