马上注册,结交更多好友
您需要 登录 才可以下载或查看,没有账号?立即注册
×
以前的时候用其他主题时加过这个留言多少条后显示vip等级的,后来换了主题就没有再加,今天突然想加上,可是忘了怎么加了,就找啊找啊的,找各种代码。坑爹的百度经验,代码是错误的,害死我了,幸亏我提前将主题源文件下载下来了,出错上传覆盖就是,错了N次噢!!!!坑!!!!啊!!!!!百度经验错误了都没地方举报。。。。 注意:据说,复制到wordpress的代码,再粘贴到其它地方好像标点还是什么不行,会出现代码失灵等现象。具体解决方法,好像是用插件或代码限制wordpress对代码进行转换,具体怎么弄我不知道。代码失灵这个的确遇到过。 第一步:使用Notepad++或者UltraEdit打开主题里面的functions.php文件,在最后一个?>之前加入下面代码: - //获取访客VIP样式
- functionget_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'';
- else if($author_count>=20 &&$author_count<40)
- echo'';
- else if($author_count>=40 &&$author_count<80)
- echo'';
- else if($author_count>=80 &&$author_count<160)
- echo'';
- else if($author_count>=160 &&$author_count<320)
- echo'';
- else if($author_count>=320 &&$author_count<640)
- echo'';
- else if($author_count>=640)
- echo'';
- }
复制代码标亮的一行就是重点了,就是根据评论人的Email,查询他的评论数量,来判断对应的VIP等级,这个代码很多地方可以定制的,比如样式可以自己定义,可以直接改成文字都可以,不用class样式;判断VIP等级的条件可以自己定义,大家可以按需要修改成自己满意的。 第二步:在适合的地方调用此函数,因为每个主题基本都不一样,所以需要大家找到你的主题调用评论的地方,fengyun主题在functions.php里,搜索 - <?php comment_author_link() ?>
复制代码在后面加入下面的代码
- <?php get_author_class($comment->comment_author_email,$comment->user_id)?>
复制代码 如果需要再添加一个“博主认证”的功能,那么就在以上代码之后再添加下面代码:- <?phpif(user_can($comment->user_id, 1)){echo"<a title='博主认证' class='vip'></a>";}; ?>
复制代码 第三步:加入样式所对应的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下面去
|