杂谈漫话 |JiuGoe

#首次评论以获取最近评论#
  • {{ item.name }}
  • 一、「纯代码」实现步骤
  • 二、「插件法」实现步骤:
  • 首 页
  • 生活杂谈
  • 设计笔札
  • 折腾合集
  • 文章归档
  • 豆瓣书影
  • 好物清单
  • 链 接

Apple DEEPAL HiRyzen 书影娱乐 折腾合集 生活杂谈 设计笔记 足 迹 跨年日记

  • ANKER安可 2025/05/12
    你竟然自己装修啊,牛逼啊,柜子也自己打嘛...
  • 南巷清风 2025/03/01
    这是在努力建设婚房了吗?卫生间的防水很重...
  • 老王 2025/02/17
    可以哦,多才多艺
  • 拾一 2025/01/20
    5度往下就不能贴砖了呀!!要空鼓的呀

More Related
  • Wing 魔改记录篇 6月 5, 2023
  • 数据库结构及表释义 4月 28, 2018
  • 分享 – 添加自定义评论表情包 4月 27, 2018
  • 解决图片上传后台不显示 12月 12, 2017
  • 小站优化总结「1」 – 那些踩过的坑 5月 19, 2018

分享 – 添加“评论等级”和“博主认证”

  • JiuGoe
  • 2018-05-13
  • 3

今天增加了博主验证图标和评论等级图标显示。只要在本站评论数超过2个,就会显示Vip1的标记。而且博主验证图标也是相当之酷!实际效果见文末,实现的方法有两种,一种是「纯代码」,另一种是「插件法」。
「纯代码」的方法我实践失败,不知是不是因为用了Ajax的原因,希望有实践成功的伙伴能留言分享下。纯代码方法来自「中国行:轻语博客」,网上也有很多教程,基本一样。现在把实现的方案步骤记下来,也算是一份笔记~

一、「纯代码」实现步骤

  • 主题的 functions.php 添加下面的代码:
//评论等级和博主认证
function get_author_class($comment_author_email,$user_id){
    global $wpdb;
    $author_count = count($wpdb->get_results(
    "SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' "));
    /*如果不需要管理员显示VIP标签,就把下面一行的 // 去掉*/
    $adminEmail = get_option('admin_email');if($comment_author_email ==$adminEmail) return;
    if($author_count>=10 && $author_count<20)
        echo '<a class="vip1" title="评论达人 LV.1"></a>';
    else if($author_count>=20 && $author_count<40)
        echo '<a class="vip2" title="评论达人 LV.2"></a>';
    else if($author_count>=40 && $author_count<80)
        echo '<a class="vip3" title="评论达人 LV.3"></a>';
    else if($author_count>=80 && $author_count<160)
        echo '<a class="vip4" title="评论达人 LV.4"></a>';
    else if($author_count>=160 && $author_count<320)
        echo '<a class="vip5" title="评论达人 LV.5"></a>';
    else if($author_count>=320 && $author_count<640)
        echo '<a class="vip6" title="评论达人 LV.6"></a>';
    else if($author_count>=640)
        echo '<a class="vip7" title="评论达人 LV.7"></a>';
}
  • 打开主题的评论文件(一般在根目录的 comments.php 或 functions.php 里),找:
echo '<div class="comt-meta"><span class="comt-author">'.get_comment_author_link().'</span>';
  • 在下面一行添加
//会员等级调用
 get_author_class($comment->comment_author_email,$comment->user_id); if($comment->user_id == 1){echo "<a title='博主认证' class='vip'></a>";};
  • 在主题的 style.css 文件的最后,添加下面的样式代码:
/*VIP评论之星*/
.vp,.vip,.vip1,.vip2,.vip3,.vip4,.vip5,.vip6,.vip7{background: url(../images/vip.png) no-repeat;display: inline-block;overflow: hidden;border: none;}
.vp{background-position:-515px -2px;width: 16px;height: 16px;margin-bottom: -3px;}
.vp:hover{background-position:-515px -22px;width: 16px;height: 16px;margin-bottom: -3px;}
.vip{background-position:-494px -3px;width: 16px;height: 14px;margin-bottom: -2px;}
.vip:hover{background-position:-494px -22px;width: 16px;height: 14px;margin-bottom: -2px;}
.vip1{background-position:-1px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip1:hover{background-position:-1px -22px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip2{background-position:-63px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip2:hover{background-position:-63px -22px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip3{background-position:-144px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip3:hover{background-position:-144px -22px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip4{background-position:-227px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip4:hover{background-position:-227px -22px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip5{background-position:-331px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip5:hover{background-position:-331px -22px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip6{background-position:-441px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip6:hover{background-position:-441px -22px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip7{background-position:-611px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
.vip7:hover{background-position:-611px -22px;width: 46px;height: 14px;margin-bottom: -1px;}
  • 另存vip图片,添加到主题的images文件夹,上传完图片,就大功告成了:

二、「插件法」实现步骤:

  • 搜索安装 WP Comments VIP 插件;
  • 设置每个等级所需评论数;
  • 有兴趣可以修改插件的PHP文件,自定义等级名称、博主标识名称。

Danile_Lxp
5-13

5-15更新:
今天在增加说说“分页的时候”,我找到了“代码法”失败的原因。
不同的主题,get_comment_author_link()位置也不尽相同,大部分都在主题根目录下的comments.php 或 functions.php 里能找到,但我用的主题在网站根目录的wp_include下。

©2015-2025 杂谈漫话 All Rights Reserved
Modified By JiuGoe With 湘ICP备2023032388号|WordPress & Wing