张维龙博客

  • 网站首页
  • 生活随笔
  • 实用工具
  • 运维笔记
  • 数码设备
  • 兴趣爱好
  • 网络设备
  • 关于博主
  • RSS Feed
  • GitHub
  • Mail
  • WordPress

为WordPress加上“评论VIP标志”功能

  • 张维龙
  • 2012-12-13
  • 0

  WordPress的评论功能一直很好,现在QQ、微博、微信等等都带有等级和VIP认证,今天跟大家分享下我的WordPress评论的等级、VIP标志的添加方法,非常简单的哦 ^_^ ! 

comment-vip


第一步、添加模板函数(functions.php):

//评论VIP标志
function get_author_class($comment_author_email,$comment_author_url){
	global $wpdb;
	$adminEmail = 'Vailog@QQ.Com';
	$author_count = count($wpdb->get_results(
	"SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' "));
	if($comment_author_email ==$adminEmail)
		echo '';
		$linkurls = $wpdb->get_results(
		"SELECT link_url FROM $wpdb->links WHERE link_url = '$comment_author_url'");
		foreach ($linkurls as $linkurl) {
			if ($linkurl->link_url == $comment_author_url )
			echo '';
		}	
	if($author_count>=1 && $author_count<10 && $comment_author_email!=$adminEmail)
		echo '';
		else if($author_count>=10 && $author_count<20 && $comment_author_email!=$adminEmail)
		echo '';
		else if($author_count>=20 && $author_count<50 && $comment_author_email!=$adminEmail)
		echo '';
		else if($author_count>=50 && $author_count<100 && $comment_author_email!=$adminEmail)
		echo '';
		else if($author_count>=100 &&$author_count<200 && $comment_author_email!=$adminEmail)
		echo '';
		else if($author_count>=200 && $author_coun<500 && $comment_author_email!=$adminEmail)
		echo '';
		else if($author_count>=500 && $comment_author_email!=$adminEmail)
		echo '';
}

  复制以上代码,把它添加到你主题的最后一个“?>”的上面,如下图:
comment-vip-1
  其中的邮箱和/gustbook/都可以改为你的邮箱和页面地址、具体用来干嘛的可以去探索一下~


第二步、添加调用代码
  找到你评论文件中的“comment_author_link”(不同的主题稍有不同)

<?php get_author_class($comment->comment_author_email,$comment->comment_author_url)?>

  在你的博客评论文件(一般是名字有comments的php文件)中搜索“comment_author_link”,我的这个语句在“commentlists.php”中,这个不一定是一样的、也可以酌情的去寻找它,例如说我的主题评论后面都有“回应于X小时前”这一种、直接搜索“回应于”也可以!如图:
comment-vip-2
  具体的地方可以自己加代码加多几次就知道了,因为每一个主题都不一样、也就不深究了。


第三步、编写或添加CSS样式(style.css):
  有些朋友喜欢用文字的、那也就自己写样式吧,我给大家一个使用图片的(和本站的一样的)。

.vp,.vip,.vip1,.vip2,.vip3,.vip4,.vip5,.vip6,.vip7{background: url(images/commentvip.png) no-repeat;display: inline-block;overflow: hidden;border: none;}
.vp{background-position:-494px -3px;width: 16px;height: 16px;margin-bottom: -3px;}
.vp:hover{background-position:-491px -19px;width: 19px;height: 18px;margin-top: -3px;margin-left: -3px;margin-bottom: -3px;}
.vip{background-position:-515px -2px;width: 16px;height: 16px;margin-bottom: -3px;}
.vip:hover{background-position:-515px -22px;width: 16px;height: 16px;margin-bottom: -3px;}
.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;}
.btn-out,.btn-hover,.btn-down{background: url(images/vip.png) no-repeat;width: 64px;height: 23px;border:none;}
.btn-out{background-position:-659px -1px;}
.btn-hover{background-position:-724px -1px;}
.btn-down{background-position:-789px -1px;}
.input{border-radius: 1px 1px 1px 1px;border:1px solid #C5C5C5;background-color:#F6F6F6;}
.input:hover,.input:focus{background-color: white;border-color: #464646;}

  添加到style.css文件底部就可以了。
comment-vip-3
[down]把下面压缩包下载后解压的commentvip.png放到主题目录的images文件夹内。
[butdown href="https://www.zhangweilong.com/wp-content/uploads/2012/12/commentvip.zip"]图片压缩包commentvip.zip[/butdown][/down]

© 2025 张维龙博客
Theme by Wing
  • {{ item.name }}
  • {{ item.name }}