如何按评论数量显示前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 .= '
  •  comment_author_url.'" target="_blank" rel="external nofollow">'.$result->comment_author.' 共'.$result->comments_count.' 条评论,最后评论 '.human_time_diff(strtotime($result->last_commented_date)).'前
  • ';     }     $output .= '
';     echo $output; }

调用代码:

<?PHP  top_comment_authors(100); ?>
登录后复制

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

以上就是如何按评论数量显示前100名评论者的详细内容,更多请关注慧达AI工具网其它相关文章

转载请说明出处 内容投诉内容投诉
慧达seo-站长工具-seo工具-采集-发布-AI文章生成发布工具 » 如何按评论数量显示前100名评论者

慧达AI专注站群seo管理工具

查看演示 官网购买