按评论数量显示前100名评论者
如想看看自己博客上哪位博友的留言评论最多及最后的评论时间,下面一段代码会帮你实现这个功能。
可以将下面代码添加到当前主题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主题”为宗旨,累计为2000多家客户提供品质wordpress建站服务,得到了客户的一致好评。我们一直用心对待每一个客户,我们坚信:“善待客户,将会成为终身客户”。大熊wordpress能坚持多年,是因为我们一直诚信。我们明码标价(wordpress做网站需要多少钱),从不忽悠任何客户,我们的报价宗旨:“拒绝暴利,只保留合理的利润”。如果您有网站建设、网站改版、网站维护等方面的需求,请立即咨询右侧在线客服或拨打咨询热线:18324743309,我们会详细为你一一解答你心中的疑难。
写给所有做网站的朋友的一封信
现在就开始执行“1+N”互联网推广和没有开始执行的人,一两天看不出任何区别; 一两个月看来差异也是微乎其微的;但在2-5年的长远时间来看的时候,你的高质量询盘不断增加,你的互联网资产已经建立完成,对手已经很难匹敌,现在你看到这段文字的时候就是最好的开始,现在就是最好的时候,马上开始“1+N”体系的整体互联网推广吧,我们和你一起,开创互联网大未来!