您可以这样做:
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
}