问题很简单(我也不知道是不是aswer;)
我只想检查一下,类别是否具有其cat id中的子级(或是祖先级)以及函数<例如function check_category ($catid){
<注意:我只能为函数传递cat id参数,因为我需要在函数中使用它。php提前感谢。。。
............
...//true if is ancestor, false if not
return $result;
}
从其ID检查类别是否为父类别
1 个回复
最合适的回答,由SO网友:Bainternet 整理而成
您可以这样做:
function category_has_parent($catid){
$category = get_category($catid);
if ($category->category_parent > 0){
return true;
}
return false;
}
使用方法如下:if (category_has_parent(\'22\')){
//true there is a parent category
}else{
//false this category has no parent
}
更新:要检查其他方法(如果类别有子类别),可以使用get\\u categories$children = get_categories(array(\'child_of\' => id,\'hide_empty\' => 0));
if (count($children) > 1){
//has childern
}else{
//no children
}
结束