您现在的位置是:首页 > 教程 > WordPress教程WordPress教程
WordPress主题模板按评论数量显示前100名评论者的方法
张津广2023-11-01 00:44:16WordPress教程已有人查阅
导读如想看看自己博客上哪位博友的留言评论最多及最后的评论时间,下面一段代码会帮你实现这个功能。
如想看看自己博客上哪位博友的留言评论最多及最后的评论时间,下面一段代码会帮你实现这个功能。
可以将下面代码添加到当前主题functions.php中:
可以将下面代码添加到当前主题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可以控制显示数量。
本文标签:
很赞哦! ()
相关文章
随机图文
怎么删除wordpress主题链接
怎么去除wordpress主题链接去除wordpress主题链接的方法:首先打开主题文件夹:wp-content/themes/主题名称/footer.php;WordPress使用钩子主题开发避免死循环的方法
WordPress 开发时,我们经常会使用 save_post 或 create_post_tag 等钩子,以便在更新文章或分类时,增加一些附加数据,这些钩子触发的时机是发布或更新数据的时间discuz和wordpress有哪些区别
Crossday Discuz! Board(简称 Discuz!)是北京康盛新创科技有限责任公司推出的一套通用的社区论坛软件系统。自2001年6月面世以来WordPress增加百度收录的方法
利用百度站长平台提供的链接自动提交代码, 快速增加百度收录, 加快网站内容抓取。1.创建名为 “baidu_js_push.php”的文件, 内容如下(自动推送JS代码 ):
留言与评论 (共有 条评论) |