WordPress 网站按评论数量显示前100名的评论者的方法

WordPress 网站按评论数量显示前100名的评论者的方法。如想看看自己博客上哪位博友的留言评论最多及最后的评论时间,下面一段代码会帮你实现这个功能。

1、可以将下面代码添加到当前主题functions.php中:

  1. function top_comment_authors($amount = 100) {    global $wpdb;        $prepared_statement = $wpdb->prepare(        'SELECT        COUNT(comment_author) AS comments_count, comment_author, comment_author_url, MAX( comment_date ) as last_commented_date        FROM '.$wpdb->comments.'        WHERE comment_author != "" AND comment_type = "" AND comment_approved = 1        GROUP BY comment_author        ORDER BY comments_count DESC, comment_author ASC        LIMIT %d',        $amount);    $results = $wpdb->get_results($prepared_statement);    $output = '<ul class="top-comments">';    foreach($results as $result) {        $output .= '<li class="top-comment-author"><strong> <a href="'.$result->comment_author_url.'" target="_blank" rel="external nofollow">'.$result->comment_author.'</a></strong> 共'.$result->comments_count.' 条评论,最后评论 '.human_time_diff(strtotime($result->last_commented_date)).'前</li>';    }    $output .= '</ul>';    echo $output;}  

2、调用代码:

  1. <?php top_comment_authors(100); ?>  

3、将代码添加到WordPress主题模板适当位置即可,其中的数字100可以控制显示数量。

4、可以通过以上代码做一个读者排行榜。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秃头程序员宝贝

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值