typecho 显示用户文章总数量
发表于 : 2018年 3月 1日 09:07
转自https://qqdie.com/archives/typecho-author-allpostsnum.html
在functions.php中加入如下函数
显示当前作者文章总数量调用代码如下(适用于post.php,author.php, 或者index.phpwhile 循环中等等)
显示特定uid作者文章总数量调用代码如下 (适用于任意模板文件)
//数字1改成对应作者的uid即可
疑问
SQL好像有个COUNT语法直接可以返回符合结果的数量,但是我没写出来,不知道怎么回事,怎么写都报错!
在functions.php中加入如下函数
代码: 全选
function allpostnum($id){
$db = Typecho_Db::get();
$co=$db->select ('table.contents.authorId')->from ('table.contents')->where ('table.contents.authorId=?',$id)->where('table.contents.type=?', 'post');
$postnum = count($db->fetchAll($co));
echo $postnum;
}
显示当前作者文章总数量调用代码如下(适用于post.php,author.php, 或者index.phpwhile 循环中等等)
代码: 全选
<?php allpostnum($this->author->uid); ?>
显示特定uid作者文章总数量调用代码如下 (适用于任意模板文件)
代码: 全选
<?php allpostnum(1); ?>
//数字1改成对应作者的uid即可
疑问
SQL好像有个COUNT语法直接可以返回符合结果的数量,但是我没写出来,不知道怎么回事,怎么写都报错!