wordpress如果获取较大/较小的类别值

wordpress如果获取较大/较小的类别值,wordpress,Wordpress,我在category.php中有代码 <?php $getcatid = get_query_var('cat'); ?> <?php $args = array('child_of' => ''.$getcatid.'', 'parent' => ''.$getcatid.'', 'hide_empty' => 0);?> <?php $categories = get_categories($args); foreach ($categorie

我在category.php中有代码

<?php $getcatid = get_query_var('cat'); ?>
<?php $args = array('child_of' => ''.$getcatid.'', 'parent' => ''.$getcatid.'', 'hide_empty' => 0);?>
<?php $categories = get_categories($args); foreach ($categories as $cat) { ?>
<?php $getid = $cat->cat_ID; ?>

如何将数量子类别值检查为:

如果$categories<4($getcatid有较小的4个子项)
回显代码循环

else(如果$categories>4)
echo代码循环


任何想法。谢谢

如果您使用
get\u categories
检索类别,您可以轻松地对结果运行
,以检查有多少条目。然后,您可以使用该数字进行比较

可能是这样(未经测试):


i用户代码
和所有类别回显其他类别。如何检查值子类别<4?回答得很好。非常感谢。
 <?php 
   // stripped your code out
   $categories = get_categories($args);

   if(count($categories) > 4) { }
   else { }
 ?>