wordpress自带的分类统计函数只能统计小分类的文章数,如果想要获取大分类的文章数量只能通过自定义函数来实现了。以下函数放入function,调用代码<?php ludou_get_cat_postcount(分类ID); ?>
获取大分类文章总数。ludou_get_cat_postcount(530);
function ludou_get_cat_postcount($id) {
// 获取当前分类信息
$cat = get_category($id);
// 当前分类文章数
$count = (int) $cat->count;
// 获取当前分类所有子孙分类
$tax_terms = get_terms('category', array('child_of' => $id));
foreach ($tax_terms as $tax_term) {
// 子孙分类文章数累加
$count +=$tax_term->count;
}
return $count;
}


湘公网安备43020002000238