在functions.php中加入如下函数

function allpostnum($id){
$db = Typecho_Db::get();
$postnum=$db->fetchRow($db->select(array('COUNT(authorId)'=>'allpostnum'))->from ('table.contents')->where ('table.contents.authorId=?',$id)->where('table.contents.type=?', 'post'));
$postnum = $postnum['allpostnum'];
return $postnum;
}

显示当前作者文章总数量调用代码如下(适用于post.php,author.php,或者index.phpwhile循环中等等)

author->uid); ?>

代码解析

$db = Typecho_Db::get();
//获取数据库
$postnum=$db->fetchRow($db->select(array('COUNT(authorId)'=>'allpostnum'))->from ('table.contents')->where ('table.contents.authorId=?',$id)->where('table.contents.type=?', 'post'));
//按条件查询数据,将符合结果的条数生成一个数组
//print_r($postnum);取消注释可调试显示结果
$postnum = $postnum['allpostnum'];
//获取作者文章总数量
return $postnum;
//返回作者文章总数量,用return能够更加方便的处理事情
TAGS:typecho
!如链接失效请在下方留言。本站所有资源均来源于网络,版权属于原作者!仅供学习参考,本站不对您的使用负任何责任。如果有侵权之处请第一时间联系我们删除,敬请谅解!