typecho显示当前作者文章总数量
在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循环中等等)
<?php echo allpostnum($this->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能够更加方便的处理事情
文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/57
0 评论
3.1k
发表评论
热门文章
自媒体博客Spimes主题41w 阅读
Spimes主题专为博客、自媒体、资讯类的网站设计....
Splity博客双栏主题14w 阅读
仿制主题,Typecho博客主题,昼夜双版设计,可....
vCard主题个人简历主题13w 阅读
一款个人简历主题,可以简单搭建一下,具体也比较简单....
Spzac个人资讯下载类主题12w 阅读
用于作品展示、资源下载,行业垂直性网站、个人博客,....
热评文章
自媒体博客Spimes主题421 评论
Splity博客双栏主题191 评论
Spzac个人资讯下载类主题89 评论
Splinx博客图片主题35 评论
Spzhi知识付费社区主题34 评论
三栏清新博客S_blog主题31 评论
vCard主题个人简历主题29 评论
Pure轻简主题28 评论
最新评论
bluejay21st
1月30日
我是作者,很意外我的插件会被转载,非常感谢。因为平时比较忙,改了博客的域名但是并没有及时做重定向以及更新插件,十分抱歉。
大家如果需要可以去Github下载我的插件:
https://github.com/bluejay21st/Typecho-BaiduSeo
https://github.com/bluejay21st/Typecho-Sitemap
chenyu
3天前
[已回复]
怎么配置主题 没看到教程