给 WordPress 评论者添加等级显示,在一定程度上能够刺激用户发言的积极性,今天雅兮网就分享下目前在用的评论样式以及实现代码!作为一个博客型站点,评论功能起着举足轻重的作用,可以说访客的一言一语让整个站点“活”起来了。这时候适当给评论者加个评论等级,更有种锦上添花的感觉。一方面可以很直观的看到哪些是忠实的读者,另一外面也在一定程度上刺激了读者发言的兴趣。有朋友留言咨询,今天雅兮网就分享下目前在用的评论样式以及实现代码!
上图所示是目前在用的评论等级样式,其中包含评论者等级显示、站长认证、友情链接认证。其原理是查询数据库根据评论者邮箱已评论条数显示不同的内容;友链认证是根据读者填入的链接地址判断是否为友情链接而输出内容;站长认证是判断读者填入的邮箱是否为站长输出内容,为了防止有人冒充站长进行留言,建议开启《WordPress 禁止冒充管理员评论》功能。
至于输出什么内容,本站使用的是直接输出字体图标,您可酌情修改为文字或图片等;将如下代码放入主题函数模板中(functions.php):
- //评论VIP标志
- function get_author_class($comment_author_email,$comment_author_url){
- global $wpdb;
- $adminEmail = '此处写入站长邮箱';
- $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 '<a class="vp" target="_blank" href="/about.HTML" title="经鉴定,这货是站长"><i class="wi wi-crown"></i><span class="lv">站长</span></a>';
- $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 '<a class="vip" target="_blank" href="/links.html" rel="external nofollow" title="合作商或友情链接认证"><i class="wi wi-heart"></i></a>';
- }
- if($author_count>=1 && $author_count<10 && $comment_author_email!=$adminEmail)
- echo '<a class="vip1" target="_blank" href="/about.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" title="评论之星 LV.1"><i class="wi wi-level-1"></i></a>';
- else if($author_count>=10 && $author_count<20 && $comment_author_email!=$adminEmail)
- echo '<a class="vip2" target="_blank" href="/about.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" title="评论之星 LV.2"><i class="wi wi-level-2"></i></a>';
- else if($author_count>=20 && $author_count<50 && $comment_author_email!=$adminEmail)
- echo '<a class="vip3" target="_blank" href="/about.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" title="评论之星 LV.3"><i class="wi wi-level-3"></i></a>';
- else if($author_count>=50 && $author_count<100 && $comment_author_email!=$adminEmail)
- echo '<a class="vip4" target="_blank" href="/about.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" title="评论之星 LV.4"><i class="wi wi-level-4"></i>/a>';
- else if($author_count>=100 && $author_count<200 && $comment_author_email!=$adminEmail)
- echo '<a class="vip5" target="_blank" href="/about.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" title="评论之星 LV.5"><i class="wi wi-level-5"></i></a>';
- else if($author_count>=200 && $author_count<500 && $comment_author_email!=$adminEmail)
- echo '<a class="vip6" target="_blank" href="/about.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" title="评论之星 LV.6"><i class="wi wi-level-6"></i></a>';
- else if($author_count>=500 && $comment_author_email!=$adminEmail)
- echo '<a class="vip7" target="_blank" href="/about.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" title="评论之星 LV.7"><i class="wi wi-level-7"></i></a>';
- }
将下面函数放入到评论列表模板里,一般放在评论者昵称后面:
- <?php get_author_class($comment->comment_author_email,$comment->comment_author_url)?>
样式代码就不贴出来了,大家可根据自己的实际情况,进行修改以及样式调整。刷新页面,是不是已经实现了呢?
WordPress 评论等级博主及友链认证
- 此资源下载价格为2元立即购买(VIP 免费)立即升级