
如想看看自己博客上哪位博友的留言评论最多及最后的评论时间,下面一段代码会帮你实现这个功能。
可以将下面代码添加到当前主题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可以控制显示数量。
可以通过以上代码做一个读者排行榜。
本站除原创内容,其余内容均收集自互联网,仅限用于学习和研究目的,本站不对其内容的合法性、可用性承担任何责任。本站禁止以任何形式发布或转载任何违法相关信息,若您发现请立即向站长举报;用户投稿一切资源内容不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
如有版权内容,其版权均归原作者所有,本站虽力求保存原有版权信息,但因众多资源经多次转载,已无法确定其真实来源,故敬请原作者谅解!为尊重作者劳动成果,请购买正版支持作者,谢谢!若您对「HULIKU.COM」所载资源作品版权归属存有异议,请发送邮箱:ihuliku@qq.com 进行处理。
本站资源文件大多存储至云盘,如您发现图片或链接失效,请联系站长或作者,我们将及时进行更新。资源都是经过站长或作者收集测试优化后进行发布分享。如若转载请在贵站文内以超链形式注明狐狸库文章出处,谢谢合作!













![WordPress子比主题美化教程合集[2023/04/17]-狐狸库](https://huliku.com/pic/2023032607024935.png)
![狐狸库自定义子比主题底部footer页脚美化(自适应)[06.26]更新-狐狸库](https://huliku.com/pic/2023062610013835.png)






















请登录后查看评论内容