分页: 1 / 1

typecho统计当前分类和子分类文章总数

发表于 : 2018年 4月 7日 10:30
jrotty
typecho发布一篇文章,然后只勾选子分类,然后发布。
父分类输出分类的文章数量,并没有包含这个新发布的文章。

于是乎,垃圾博主啊用了点时间(一个半小时)写出了个函数,来解决这个问题

代码: 全选

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

Re: typecho统计当前分类和子分类文章总数

发表于 : 2018年 4月 7日 12:04
ClayMore
韩厨网需要

Re: typecho统计当前分类和子分类文章总数

发表于 : 2018年 4月 7日 20:41
韩厨网
问题以解决*^_^*
谢谢大家想着帮我
在此感谢支持与帮助

Re: typecho统计当前分类和子分类文章总数

发表于 : 2018年 4月 8日 07:26
jrotty
ClayMore 写了:韩厨网需要

就是帮他弄才写的,之前我自己需要然而不会写,现在会写了自己又不需要了 :lol: