开发者

is_subcategory(); function for wordpress

开发者 https://www.devze.com 2023-01-17 09:41 出处:网络
hi i know there are many nice functions in wordpress like is_page(), is_single(), is_category();... do u know how i can create a is_subcategory() function?开发者_JS百科

hi i know there are many nice functions in wordpress like is_page(), is_single(), is_category();...

do u know how i can create a is_subcategory() function?

开发者_JS百科

thanks a million.


There is not a is_subcategory() function but you can get the children (sub category) of a category and use as a conditional statement.

<?php
global $ancestor;
$childcats = get_categories('child_of=' . $cat . '&hide_empty=1');
foreach ($childcats as $childcat) {
  if (cat_is_ancestor_of($ancestor, $childcat->cat_ID) == false){
   //do stuff
  }
}
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消