HI,欢迎来到我爱模板网!

按评论数量显示前100名评论者

如想看看自己博客上哪位博友的留言评论最多及最后的评论时间,下面一段代码会帮你实现这个功能。可以将下面代码添加到当前主题functions.php中:function top_comment_authors($amount = 100) { global $wpdb; $prepared_statement = $wpd...

如想看看自己博客上哪位博友的留言评论最多及最后的评论时间,下面一段代码会帮你实现这个功能。

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

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;}

调用代码:

<?php top_comment_authors(100); ?>

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

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

WordPress阅读设置

2023-2-16 15:51:40

wordpress教程

让WordPress文章按最后更新时间排序总结

2023-2-16 15:51:41

【腾讯云】11.11云上盛惠!云服务器首年1.8折起,买1年送3个月!
11.11云上盛惠!海量产品·轻松上云!云服务器首年1.8折起,买1年送3个月!超值优惠,性能稳定,让您的云端之旅更加畅享。
查看更多相关信息>>
站长

(工作日 10:00 - 22:30 为您服务)

2026-01-30 06:58:32

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

猜你想问:

  • 购买的模板免费包安装吗?

  • 这个演示地址有吗?

  • 购买vip会员可以下载哪些模板?

您的留言我们已经收到,我们将会尽快跟您联系!
取消
立即选择任一渠道联系我们