wordpress获取文章评论数过滤掉作者代码分享
wordpress获取文章评论数过滤掉作者代码分享
发布时间:2016-12-23 来源:查字典编辑
摘要://获取文章评论数,不包含作者自己functionget_comments_number_filter_author(){global$wp...

//获取文章评论数,不包含作者自己

function get_comments_number_filter_author() {

global $wpdb, $post;

//需要过滤作者的名称

$author = '作者名称';

$comments = $wpdb->get_results("SELECT count(0) as total FROM $wpdb->comments WHERE comment_post_ID = $post->ID AND comment_type = '' AND comment_approved = '1' AND comment_author != '$author'");

return $comments[0]->total;

}

代码原理比较简单,就是自己编写sql语句从comments表示获取评论总数,其中不包括文章作者的评论。

将该方法复制到主题的funtions.php文件,在需要的地方调用就行了。

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新WordPress学习
热门WordPress学习
CMS教程子分类