最新活动:买一送一!升级会员,最高返 500 抵扣券! 立即查看

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

如想看看自己博客上哪位博友的留言评论最多及最后的评论时间,下面一段代码会帮你实现这个功能。 可以将下面代码添加到当前主题functions.php中: function top_comment_authors($amount = 100) { global $wpdb; $prepared_statement = $w...
按评论数量显示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 = '<ul class="top-comments">';
    foreach($results as $result) {
        $output .= '<li class="top-comment-author"><strong> <a href="'.$result->comment_author_url.'" target="_blank" rel="external nofollow">'.$result->comment_author.'</a></strong> 共'.$result->comments_count.' 条评论,最后评论 '.human_time_diff(strtotime($result->last_commented_date)).'前</li>';
    }
    $output .= '</ul>';
    echo $output;
}

调用代码:

<?php top_comment_authors(100); ?>

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

可以通过以上代码做一个读者排行榜。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

WordPress主题集成图片暗箱特效

2023-2-16 23:46:17

wordpress教程

更新版本下载失败 “Not Found WordPress”

2023-2-16 23:46:21

!
你也想出现在这里?立即 联系我们吧!
信息
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
搜索