惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
H
Hacker News: Front Page
Stack Overflow Blog
Stack Overflow Blog
B
Blog
I
InfoQ
GbyAI
GbyAI
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
F
Full Disclosure
Hacker News - Newest:
Hacker News - Newest: "LLM"
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
T
Tailwind CSS Blog
S
Secure Thoughts
P
Privacy International News Feed
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LINUX DO - 最新话题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Cybersecurity and Infrastructure Security Agency CISA
Last Week in AI
Last Week in AI
W
WeLiveSecurity
Google Online Security Blog
Google Online Security Blog
P
Privacy & Cybersecurity Law Blog
D
DataBreaches.Net
Engineering at Meta
Engineering at Meta
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
I
Intezer
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Project Zero
Project Zero
V2EX - 技术
V2EX - 技术
H
Heimdal Security Blog
博客园 - Franky
阮一峰的网络日志
阮一峰的网络日志
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
H
Help Net Security
Martin Fowler
Martin Fowler
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
G
GRAHAM CLULEY
博客园 - 【当耐特】

李锋镝的博客

LiteLLM 本地代理搭建 Claude-HUD 使用文档 Kratos+ —— Kratos 主题二次开发记录 译文:如何将单体应用拆解为微服务 codebase-memory-mcp 极简完整使用指南 Claude Haiku 4.5、Claude Sonnet 4.6、Claude Opus 4.7 区别以及各自的新特性 SchedulingConfigurer详解 踩坑60+次后,我终于搞懂 Claude Skill 怎么写才会真的触发 Everything Claude Code 详细使用文档 配置Jackson使用字段而不是getter/setter来序列化和反序列化 这个域名注册整整十年了,十年时间,真快啊 Claude Code全维度实战指南:从入门到精通,解锁AI编程新范式 Apollo配置中心中的protalDB的作用是什么 org.apache.ibatis.plugin.Interceptor类详细介绍及使用 岁末 Excel2016右键新建工作表,打开时提示“因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配。”的解决办法 wordpress增加说说功能 Java 为什么有这么多 “O”? 别再背线程池的七大参数了,现在面试官都这么问 2024年11月1号 农历十月初一 我的第一个WordPress插件:Dylan Custom Plugin上线了 推荐一款比较养眼的Xshell配色方案 hnswlib installation failed 开工啦~ 阳了... MybatisCodeHelperPro激活 @Async注解的坑 新买的笔记本发货啦…… 这个中秋节感觉过的好累啊 IDEA下载源码报:Cannot connect to the Maven process. Try again later. RocketMQ的push消费方式实现详解 看病难~取药难~~ 笑死、腹肌……根本不可能有腹肌的~~ 居家办公了~ C# 11 的这个新特性,我愿称之最强! IntelliJ IDEA 2020.3.x永久白嫖(Windows/Mac) IDEA无限试用方法【2020.3最新亲测有效】 SpringBoot使用注解的方式构建Elasticsearch查询语句,实现多条件的复杂查询 UUID太长怎么办?快来试试NanoId 忽然发现,在校大学生可以免费领一年有道云笔记会员~ 醒醒~补个税了 使用itext和freemarker来根据Html模板生成PDF文件,加水印、印章 来来来,用python画一个冰墩墩儿 SpringBoot整合GraphQL入门教程 办理居住证困难重重啊! 妈呀,昨天晚上睡觉做了一晚上的梦,可累死我了 感觉Typecho很简洁啊…… WordPress的自动更新好烦啊 BeanCopier工具类(性能优化工具类) 内存屏障浅析 居住证可算是申请通过了…… 试了下壁挂炉供暖 关于重阳节 居住证签注... Spring Boot 2.x使用PostgreSQL数据库 十一节后开工头一天,修了个耳机…… 玉楼春·尊前拟把归期说 nginx反向代理配置去除前缀 1931→2021! Navicat Premium数据库账号密码解密 百度的索引量数据现在有点儿太夸张了吧? 哇塞~这个小姐姐实在太惊艳了…… 关于8月29号下午博客故障的一些记录 如何形象的描述反应式编程中的背压(Backpressure)机制? 基于Java8的Either类 海琴烟~~~ JMX监控权限认证配置 IntelliJ IDEA 2019.3.3 永久激活 破解[Windows] SpringBoot整合Elasticsearch详细步骤以及代码示例(附源码) SpringBoot整合Elasticsearch游标查询(scroll) GitLab创建新项目,初次提交命令和流程 吐槽下Google浏览器~ 从零搭建Spring Cloud Gateway网关(一) 从零搭建Spring Cloud Gateway网关(二)—— 打印请求响应日志 博客有logo啦 你的答案 数据库事务的一点简单总结 Spring Boot发展史(Spring Boot介绍) 【漫画】戏说外行对程序员的误会有多深 【收藏】从面试官角度观察到的程序员技能瓶颈,同时给出突破瓶颈的建议 Git中.gitignore文件不起作用的解决办法 背影 - 朱自清 jmap命令(jdk1.8) 彻底搞懂mysql日志系统binlog,redolog,undolog 出院了~~~ linux中ftp查看不到文件列表的问题 PHP版本怎么更新啊…… 成语接龙 StarUML4.0破解文件 Java SPI详解 WordPress评论框增加自定义表情 因在公司上不正经网站,我没过试用期… 优化了MYSQL大量写入问题,老板奖励了1000块给我 不慌不忙的坚强(林徽因39段最美文字!) ConcurrentHashMap常用方法源码解析(jdk1.8) 我是如何失去团队掌控的? HBASE填坑日志 关闭apache httpclient4.5 DEBUG日志 使用OpenShift搭建k8s集群 SonarQube Scanner的配置与使用简介
WordPress实现用户评论等级排行榜插件
李锋镝 · 2026-01-11 · via 李锋镝的博客

前几天逛博客,看到大家的博客都有很多好玩的页面,比如Hary大佬的博客中有一个互动排行榜页面。

还有皮总的博客皮皮社上面的评论用户等级。

感觉大家的网站都很有趣,于是也打算自己实现一个评论等级排行榜,所以就写了一个WordPress插件。

插件主要功能如下:

  • 统计用户评论数
  • 通过简码的方式展示评论用户排行榜

简码实现的代码很简单:

function cur_render_rank_top($atts) {

    $atts = shortcode_atts(array(
        'num'         => 10,
        'avatar_size' => 64,
        'columns'     => 3,
        'title'       => '评论等级排行榜',
    ), $atts, 'comment_rank_top');

    $limit = min(intval($atts['num']), 50);
    $avatar_size = intval($atts['avatar_size']);
    $avatar_size = $avatar_size < 32 ? 32 : $avatar_size;
    $columns = intval($atts['columns']);
    $columns = $columns < 1 ? 1 : ($columns > 4 ? 4 : $columns);
    $custom_title = esc_html($atts['title']);

    global $wpdb;
    $table_prefix = $wpdb->prefix;

    $top_users = $wpdb->get_results($wpdb->prepare(
        "SELECT
            COUNT(*) as comment_count,
            comment_author_email,
            comment_author,
            comment_author_url
         FROM {$table_prefix}comments
         WHERE comment_approved = '1' AND user_id != 1
           AND comment_type NOT IN ('pingback', 'trackback')
         GROUP BY comment_author
         ORDER BY comment_count DESC
         LIMIT %d",
        $limit
    ), ARRAY_A);

    if (empty($top_users)) {
        return sprintf(
            '<div class="comment-rank-top">
                <h3 class="rank-top-title">%s</h3>
                <p class="rank-top-empty">暂无符合条件的评论数据</p>
            </div>',
            $custom_title
        );
    }

    $html = '<div class="comment-rank-top">';
    $html .= sprintf('<h3 class="rank-top-title">%s</h3>', $custom_title);
    $html .= sprintf('<div class="rank-top-flex" style="--columns: %d;">', $columns);

    foreach ($top_users as $index => $user) {
        $comment_count = intval($user['comment_count']);
        $email = esc_attr($user['comment_author_email']);
        $name = esc_html($user['comment_author']);
        $url = esc_url($user['comment_author_url']);
        $rank = cur_get_user_rank($comment_count);

        $card_class = '';
        if ($index === 0) {
            $card_class = 'rank-card-1st';
            $rank_badge = '<span class="rank-top-badge rank-1st">🏆 第1名</span>';
        } elseif ($index === 1) {
            $card_class = 'rank-card-2nd';
            $rank_badge = '<span class="rank-top-badge rank-2nd">🥈 第2名</span>';
        } elseif ($index === 2) {
            $card_class = 'rank-card-3rd';
            $rank_badge = '<span class="rank-top-badge rank-3rd">🥉 第3名</span>';
        } else {
            $rank_badge = sprintf('<span class="rank-top-badge">第%d名</span>', $index + 1);
        }

        $avatar = get_avatar($email ?: $name, $avatar_size, '', $name, array(
            'class' => 'rank-top-avatar',
            'alt'   => $name . '的头像'
        ));

        $user_name_html = $url ? sprintf('<a href="%s" target="_blank" rel="nofollow">%s</a>', $url, $name) : $name;
        $rank_tag = sprintf('<span class="comment-user-rank %s">%s</span>', esc_attr($rank['class']), esc_html($rank['name']));

        $html .= sprintf(
            '<div class="rank-top-card %s">
                %s
                <div class="rank-top-card-inner">
                    <div class="rank-top-avatar-wrap" style="width: %dpx; height: %dpx;">%s</div>
                    <div class="rank-top-name">%s</div>
                    <div class="rank-top-meta">
                        %s
                        <span class="rank-top-count">评论数:%d</span>
                    </div>
                </div>
            </div>',
            $card_class,
            $rank_badge,
            $avatar_size,
            $avatar_size,
            $avatar,
            $user_name_html,
            $rank_tag,
            $comment_count
        );
    }

    $html .= '</div></div>';

    return $html;
}

add_shortcode('comment_rank_top', 'cur_render_rank_top');

css样式比较简单,这里就不贴出来了,大家可以根据自己的喜好制定自己喜欢的样式即可。

我这里给榜一、榜二和榜三的大佬添加不同的样式,比如给榜一、榜二和榜三的标签添加不同的颜色,给榜一、榜二和榜三的标签添加不同的图标,用来彰显三位大佬的身份。

展示效果大家可以在这个页面看到:https://www.lifengdi.com/comment-user-rank

简码用法如下:
简码:comment_rank_top
示例:[comment_rank_top num="10" columns="3" title="🔥 互动热榜"]
参数说明:

  • title: 排行榜标题(支持自定义,默认"评论等级排行榜")
  • columns: 列数(1~4,默认3)
  • num: 显示数量(默认10,最大50)
  • avatar_size: 头像尺寸(默认64px,最小32px)

大家有什么好的想法也可以提出来,我来负责实现。😉

除非注明,否则均为李锋镝的博客原创文章,转载必须以链接形式标明本文链接

本文链接:https://www.lifengdi.com/article/cha-jian/4626