0

我一直在四处寻找,似乎找不到(或拼凑)检查当前类别或帖子是否是某个类别的孙子的代码。基本上,有什么方法可以正确编码:

<?php if ( is_grandchild(147) || in_grandchild(147) ) { do something } ?>
4

1 回答 1

0
function get_topmost_parent($post_id){
  $parent_id = get_post($post_id)->post_parent;
  if($parent_id == 0){
    return $post_id;
  }else{
    return get_topmost_parent($parent_id);
  }
}

试试这个将返回最上面的父母!

于 2013-08-30T12:30:23.317 回答