按评论数量显示前100名评论者

如想看看自己博客上哪位博友的留言评论最多及最后的评论时间,下面一段代码会帮你实现这个功能。

可以将下面代码添加到当前主题functions.php中:

  1.  top_comment_authors( = 100) {
  2.      ;
  3.          = ->prepare(
  4.         \’SELECT
  5.         (comment_author) AS comments_count, comment_author, comment_author_url, MAX( comment_date )  last_commented_date
  6.         FROM \’.->comments.\’
  7.         WHERE comment_author !=  AND comment_type =  AND comment_approved = 1
  8.         GROUP BY comment_author
  9.         ORDER BY comments_count DESC, comment_author ASC
  10.         LIMIT %d\’,
  11.         );
  12.      = ->get_results();
  13.      = \'<ul =>\’;
  14.     (  ) {
  15.          .= \'<li =><strong> <a href= target= rel=>\’.->comment_author.\'</a></strong> 共\’.->comments_count.\’ 条评论,最后评论 \’.human_time_diff((->last_commented_date)).\’前</li>\’;
  16.     }
  17.      .= \'</ul>\’;
  18.      ;
  19. }

调用代码:

  1. <?php top_comment_authors(100); ?>

将代码添加到WordPress主题模板适当位置即可,其中的数字100可以控制显示数量。

通过上面的代码可以演化成类似我博客的:读者排行

    © 版权声明
    THE END
    喜欢就支持一下吧
    点赞0 分享
    评论 抢沙发

    请登录后发表评论

      暂无评论内容