我正在尝试制作一个分类计数器,但它实际上不起作用。我想有一个所有类别的通用计数器(1168),稍后我会显示它。例如:
第一级是第二级的6个类别第三级的13个类别第四级的56个类别第五级的158个类别第六级的934个类别如何实现get_terms
?
到目前为止,我已经尝试了很多事情:
我已经尝试了很多事情。因此,我开始手动选择我需要的类别ID,只是为了总结。。。但它又长又贵。
// ----- 2 level class -----
$args = array(\'parent\' => 5593);
$categories_cnt = count(get_categories( $args ));
$type1 = $categories_cnt;
// echo \'There are \'. $categories_cnt .\' subcategories in this category\';
$args = array(\'parent\' => 1104);
$categories_cnt = count(get_categories( $args ));
$type2 = $categories_cnt;
// echo \'There are \'. $categories_cnt .\' subcategories in this category\';
$args = array(\'parent\' => 2266);
$categories_cnt = count(get_categories( $args ));
$type3 = $categories_cnt;
//echo \'There are \'. $categories_cnt .\' subcategories in this category\';
$args = array(\'parent\' => 3507);
$categories_cnt = count(get_categories( $args ));
$type4 = $categories_cnt;
// echo \'There are \'. $categories_cnt .\' subcategories in this category\';
$args = array(\'parent\' => 4102);
$categories_cnt = count(get_categories( $args ));
$type5 = $categories_cnt;
// echo \'There are \'. $categories_cnt .\' subcategories in this category\';
$args = array(\'parent\' => 4376);
$categories_cnt = count(get_categories( $args ));
$type6 = $categories_cnt;
// echo \'There are \'. $categories_cnt .\' subcategories in this category\'; $summ = $type1 + $type2 + $type3 + $type4 + $type5 + $type6;
echo ($summ).\' 3vl\';
// ----- 3 level -----
// 5596 5599 5603 5605 5607 5610 5613 1609 1613 1615 1617 1634 1636 1638 1640 1642 1649 1660 1664 1748 1751 1762 1764 1766 1768 1772 1774 1777 1799 1801 1803 1823
// 1834 1836 1147 1208 1219 1222 1236 1238 1240 1214 1242 1244 1246 1262 1267 1271 1274 1281 1287 1160 1162 1171 1173 1175 1164 1185 1189 1191 1198 1200 1203 1205
// 1217 1298 1310 1312 1315 1326 1328 1331 1337 1340 1344 1346 1349 1352 1357 1361 1363 1365 1374 1376 1378 1381 1385 1387 1389 1391 1393 1395 1399 1401 1406
// wp_list_categories ();
等等。。。我试着让
wp_list_categories
函数(在这里可以使用depth参数),但此函数不知道如何计算返回的元素数。