父分类输出分类的文章数量,并没有包含这个新发布的文章。
于是乎,垃圾博主啊用了点时间(一个半小时)写出了个函数,来解决这个问题
代码: 全选
function fenleinum($id){
$db = Typecho_Db::get();
$po=$db->select('table.metas.count')->from ('table.metas')->where ('parent = ?', $id);
$pom = $db->fetchAll($po);
$num = count($pom);
$shul = 0;
for ($x=0; $x<$num; $x++) {
$shul=$pom[$x]['count']+$shul;
}
$shu=$db->fetchAll($db->select('table.metas.count')->from ('table.metas')->where ('mid = ?', $id))[0]['count']+$shul;
echo $shu;
}
前台调用,可以在分类列表循环中输入下面代码,分类mid需要根据自己的代码自填
代码: 全选
<?php fenleinum(分类mid); ?>
文章转自https://qqdie.com/archives/category-num.html