wordpress建站教程栏目给大家介绍按评论数量显示前100名评论者的方法,希望对需要的朋友有所帮助! 如想看看自己博客上哪位博友的留言评论最多及最后的评论时间,下面一段代码会帮你实现这个功能。 可以将下面代码添加到当前主题fu">
建站学院

当前位置:

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

浏览量:146次

下面由wordpress/" target="_blank">wordpress建站教程栏目给大家介绍按评论数量显示前100名评论者的方法,希望对需要的朋友有所帮助!

如何按评论数量显示前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 = &#39;<ul class="top-comments">&#39;;
    foreach($results as $result) {
        $output .= &#39;<li class="top-comment-author"><strong> <a href="&#39;.$result->comment_author_url.&#39;" target="_blank" rel="external nofollow">&#39;.$result->comment_author.&#39;</a></strong> 共&#39;.$result->comments_count.&#39; 条评论,最后评论 &#39;.human_time_diff(strtotime($result->last_commented_date)).&#39;前</li>&#39;;
    }
    $output .= &#39;</ul>&#39;;
    echo $output;
}
登录后复制

[声明]本网转载网络媒体稿件是为了传播更多的信息,此类稿件不代表本网观点,本网不承担此类稿件侵权行为的连带责任。故此,如果您发现本网站的内容侵犯了您的版权,请您的相关内容发至此邮箱【915688610@qq.com】,我们在确认后,会立即删除,保证您的版权。