下面由wordpress建站教程栏目给大家介绍按评论数量显示前100名评论者的方法,希望对需要的朋友有所帮助!
如想看看自己博客上哪位博友的留言评论最多及最后的评论时间,下面一段代码会帮你实现这个功能。
可以将下面代码添加到当前主题functions.php中:
functiontop_comment_authors($amount=100){global$wpdb;$prepared_statement=$wpdb->prepare('SELECTCOUNT(comment_author)AScomments_count,comment_author,comment_author_url,MAX(comment_date)aslast_commented_dateFROM'.$wpdb->comments.'WHEREcomment_author!=""ANDcomment_type=""ANDcomment_approved=1GROUPBYcomment_authorORDERBYcomments_countDESC,comment_authorASCLIMIT%d',$amount);$results=$wpdb->get_results($prepared_statement);$output='<ulclass="top-comments">';foreach($resultsas$result){$output.='<liclass="top-comment-author"><strong><ahref="'.$result->comment_author_url.'"target="_blank"rel="externalnofollow">'.$result->comment_author.'</a></strong>共'.$result->comments_count.'条评论,最后评论'.human_time_diff(strtotime($result->last_commented_date)).'前</li>';}$output.='</ul>';echo$output;}