我一直在搜索,但似乎找不到(或拼凑在一起)代码来检查当前类别或帖子是否是某个类别的孙子类别。基本上,有没有什么方法可以正确地编码:
<?php if ( is_grandchild(147) || in_grandchild(147) ) { do something } ?>发布于 2013-08-30 20:30:23
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);
}
}试试看,这将返回最顶层的父母!
https://stackoverflow.com/questions/18532926
复制相似问题