款款 發表於 2023-9-27 00:00:00

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

<p style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
代码如下:</p>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
//获取文章评论数,不包含作者自己<br>
function get_comments_number_filter_author() {<br>
global $wpdb, $post;<br>
//需要过滤作者的名称<br>
$author = '作者名称';<br>
$comments = $wpdb-&gt;get_results("SELECT count(0) as total FROM $wpdb-&gt;comments WHERE comment_post_ID = $post-&gt;ID AND comment_type = '' AND comment_approved = '1' AND comment_author != '$author'");<br>
return $comments-&gt;total;<br>
}</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
代码原理比较简单,就是自己编写sql语句从comments表示获取评论总数,其中不包括文章作者的评论。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
将该方法复制到主题的funtions.php文件,在需要的地方调用就行了。</p>
頁: [1]
查看完整版本: wordpress获取文章评论数过滤掉作者代码分享