查看: 61|回覆: 0

[教程] wordpress获取文章评论数过滤掉作者代码分享

[複製鏈接]

2

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2011-7-12
發表於 2023-9-27 00:00:00 | 顯示全部樓層 |閲讀模式

代码如下:


//获取文章评论数,不包含作者自己
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文件,在需要的地方调用就行了。

回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部