如何按评论数量显示前100名评论者
下面由WordPress建站教程栏目给大家介绍按评论数量显示前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 = '
- ';
foreach($results as $result) {
$output .= '
调用代码:
将代码添加到WordPress主题模板适当位置即可,其中的数字100可以控制显示数量。
以上就是如何按评论数量显示前100名评论者的详细内容,更多请关注其它相关文章!
1、本站目前拥有近 1000+ 精品收费资源,现在加入VIP会员即可全部下载。
2、本资源部分来源其他付费资源平台或互联网收集,如有侵权请联系及时处理。
SEA模板网 » 如何按评论数量显示前100名评论者
2、本资源部分来源其他付费资源平台或互联网收集,如有侵权请联系及时处理。
SEA模板网 » 如何按评论数量显示前100名评论者
发表评论