WP检查页面是否是孩子的孩子

时间:2016-10-05 13:16:59

标签: wordpress

我知道,我可以检查某个页面是父页面还是带有

的子页面
if($post->post_parent)

但是,我需要检查一个页面是否是另一个子页面的子页面,如:

  • parentpage
    • parenntpage的孩子
      • 父母页面的孩子的孩子

我需要知道该网页是否是"父母页面的孩子",或者是"母网页的孩子的孩子"

有一个解决方案吗?

谢谢

1 个答案:

答案 0 :(得分:1)

您可以使用wp_get_post_parent_id()

if ( $parent_id = wp_get_post_parent_id( $post->ID ) ) {
    // is a child
    if ( wp_get_post_parent_id( $parent_id ) ) {
         // is a child of a child
    } 
} 

您可以使用$post->ID

代替get_the_ID()
相关问题