您必须循环进行:
$p = $post;
while ( $p->post_parent ) {
$p = get_post( $p->post_parent );
}
$parent_page_link = get_permalink( $p->ID );
另一种方法是使用
get_ancestors
功能:
$ancestors = get_ancestors( $post->ID, \'page\', \'post_type\' );
$root = ( ! empty( $ancestors ) ) ? end($ancestors) : $post->ID;
$parent_page_link = get_permalink( $root );