尝试以下操作:
function is_subcategory($category = null) {
if (is_category()) {
if (null != $category){
$cat = get_category($category);
}else{
$cat = get_category(get_query_var(\'cat\'),false);
}
if ($cat->parent == 0 ){
return false;
}else{
return true;
}
}
return false;
}
用法:
//to check if the current context is a subcagetory:
if (is_subcategory()){
//its a subcategory;
}else{
//nope is aparent category
}
//to check if a specific category is a subcategory pass its ID, eg:
if (is_subcategory(12)){
//yes category with the id of 12 is a subcategory;
}else{
//nope is aparent category
}