New answers tagged


As it stands your code almost works, but it checks to see if the current page has a parent, which will always be true for both 2nd and 3rd level pages. WordPress gives us get_ancestors to retrieve an ordered array of ancestors for any hierarchical object type: get_ancestors( $object_id, $object_type ); So we can use get_ancestors( $post->ID, 'page' ) ...

Top 50 recent answers are included