WordPress 显示评论者等级并标注友链邻居和博主身份

2022-12-17

这段代码可以根据评论者的评论数显示等级或 VIP 样式,并能标注显示博主的回复,这样的做法以来可以增加用户将互动,毕竟有些网友是很有虚荣心的,如果能显示自己的等级,会吸引更多的回访和提高等级。同时如果是友情链接中的 url,则会显示为邻居,具体代码,可以根据需要自行修改:

  1. // 获取访客VIP样式
  2. function get_author_class($comment_author_email, $comment_author_url)
  3. {
  4. global $wpdb;
  5. $adminEmail = get_bloginfo('admin_email');
  6. $styleClass = 'your css style'; //添加css样式
  7. $author_count = count($wpdb->get_results(
  8. "SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' "
  9. ));
  10. if ($comment_author_email == $adminEmail) {
  11. echo '<a href="javascript:;" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  class="' . $styleClass . ' icon-vip vip7" title="博主"></a><a href="javascript:;" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  title="博主" class="icon-vip icon-admin"></a>';
  12. }
  13. $linkurls = $wpdb->get_results("SELECT link_url FROM $wpdb->links WHERE link_url = '$comment_author_url'");
  14. if ($author_count >= 1 && $author_count < 10 && $comment_author_email != $adminEmail) {
  15. echo '<a href="javascript:;" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  class="' . $styleClass . ' icon-vip vip1" title="评论达人 LV.1"></a>';
  16. } elseif ($author_count >= 10 && $author_count < 20 && $comment_author_email != $adminEmail) {
  17. echo '<a href="javascript:;" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  class="' . $styleClass . ' icon-vip vip2" title="评论达人 LV.2"></a>';
  18. } elseif ($author_count >= 20 && $author_count < 30 && $comment_author_email != $adminEmail) {
  19. echo '<a href="javascript:;" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  class="' . $styleClass . ' icon-vip vip3" title="评论达人 LV.3"></a>';
  20. } elseif ($author_count >= 30 && $author_count < 50 && $comment_author_email != $adminEmail) {
  21. echo '<a href="javascript:;" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  class="' . $styleClass . ' icon-vip vip4" title="评论达人 LV.4"></a>';
  22. } elseif ($author_count >= 50 && $author_count < 80 && $comment_author_email != $adminEmail) {
  23. echo '<a href="javascript:;" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  class="' . $styleClass . ' icon-vip vip5" title="评论达人 LV.5"></a>';
  24. } elseif ($author_count >= 80 && $author_coun < 200 && $comment_author_email != $adminEmail) {
  25. echo '<a href="javascript:;" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  class="' . $styleClass . ' icon-vip vip6" title="评论达人 LV.6"></a>';
  26. } elseif ($author_count >= 200 && $comment_author_email != $adminEmail) {
  27. echo '<a href="javascript:;" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  class="' . $styleClass . ' icon-vip vip7" title="评论达人 LV.7"></a>';
  28. }
  29. foreach ($linkurls as $linkurl) {
  30. if ($linkurl->link_url == $comment_author_url) {
  31. echo '<a class="vp" target="_blank" href="/links/" rel="external nofollow"  title="隔壁邻居的哦!" rel="noopener">隔壁邻居的哦!</a>';
  32. }
  33. }
  34. }

    这里将代码添加到当前主题 Functions.php 中。

    同时,我们需要将下面代码添加到”<?php comment_author_link();?>”评论模板下面。

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

    如果需要加上博主认证的,需要加上:

    1.     <?php get_author_class($comment->comment_author_email,$comment->user_id)?>
    2.     <?php if(user_can($comment->user_id, 1)){echo "<a title='博主认证' class='vip'></a>";}; ?>

    我们还需要添加样式:

    1. /**博客VIP评论样式**/
    2. .vp,.vip,.vip1,.vip2,.vip3,.vip4,.vip5,.vip6,.vip7{background: url(images/vip.png) no-repeat;display: inline-block;overflow: hidden;border: none;}
    3. .vp{background-position:-515px -3px;width: 14px;height: 14px;margin-bottom: -2px;}
    4. .vip{background-position:-495px -2px;width: 15px;height: 16px;margin-bottom: -3px;}
    5. .vip1{background-position:-1px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
    6. .vip2{background-position:-63px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
    7. .vip3{background-position:-144px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
    8. .vip4{background-position:-227px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
    9. .vip5{background-position:-331px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
    10. .vip6{background-position:-441px -2px;width: 46px;height: 14px;margin-bottom: -1px;}
    11. .vip7{background-position:-611px -2px;width: 46px;height: 14px;margin-bottom: -1px;}

    这里,我们需要添加图片,配合样式中调用的图片(images/vip.png)。

    
    
收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

免责声明 1、本站所发布的全部内容源于互联网搬运,(包括源代码、软件、学习资料等)本站提供的一切软件、教程和内容信息仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络收集整理,版权争议与本站无关。您必须在下载后的23个小时之内,从您的电脑或手机中彻底删除上述内容。
2、访问本站的用户必须明白,本站对所提供下载的软件和程序代码不拥有任何权利,其版权归该软件和程序代码的合法拥有者所有,如果您喜欢该程序和内容,请支持正版,购买注册,得到更好的正版服务。我们非常重视版权问题,如本站不慎侵犯您的版权请联系我们,我们将及时处理,并撤下相关内容!敬请谅解! 侵删请致信E-mail:messi0808@qq.com
3、如下载的压缩包需要解压密码,若无特殊说明,那么文件的解压密码则为www.xmy7.com
4、如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

小蚂蚁资源网 cms教程 WordPress 显示评论者等级并标注友链邻居和博主身份 https://www.xmy7.com/zh/cms/25513.html

相关文章