WordPress教程

WordPress根据最后一次评论时间来决定是否显示评论者链接

阿里云

关于对评论者链接的输出控制,之前发过一篇文章,里面讲的是经过评论者评论数量来限制能否输出显现评论者网址,总觉得上面的控制办法不给力,由于总有些忍会刷一些不走心的评论来打破上面的限制,再者,由于博客消亡的比拟快,指不定哪天某些评论数量达标的评论者的网站挂了被搞成了有害人身心安康的网站呢...

而为了“防备”这些状况,同时也加强博客网站的互动性,我们就能够采用本文标题所描绘的方式了:依据评论者最后一次评论时间来决议能否显现评论者链接。比方,评论者的最后一次评论时间间隔当前时间超越了 10 天,就制止显现评论者网站链接。PS:Dragon 主题曾经集成了这个功用哦!话不多说,直接上代码,觉得有用就不要吝啬你的评论和转发哦!

也想出现在这里?联系我们
创客主机
  1. /**
  2. * WordPress根据评论者最后一次评论时间来决定是否显示评论者链接
  3. */
  4. function lxtx_show_comment_author_link( $return , $author, $comment_ID ){
  5.     if ( !is_user_logged_in() ) { // 登录用户无鸭梨
  6.         date_default_timezone_set('PRC');
  7.         $limit_days = 10; // 天数,代表最后一次评论时间距离今天超过10天的话,则隐藏评论链接
  8.         $comment = get_comment( $comment_ID );
  9.         if ( !empty($comment->comment_author_email) ) {
  10.             $last_comment = get_comments(array(
  11.                 'author_email' => $comment->comment_author_email,
  12.                 'number' => '1',
  13.                 'orderby' => 'comment_date',
  14.                 'order' => 'DESC',
  15.                 'status' => 'approve',
  16.                 'type' => 'comment'
  17.             ));
  18.             if ( (time() - strtotime($last_comment->comment_date)) > $limit_days*24*3600 ) {
  19.                 $return = $author;
  20.             }
  21.         }else{
  22.             $return = $author;
  23.         }
  24.     }
  25.     return $return;
  26. }
  27. add_filter('get_comment_author_link','lxtx_show_comment_author_link', 10, 3);

当然,本办法仅合适运用 the_author_link()来输出评论者昵称的主题,普通来讲,常规主题都会运用这个函数。

WordPress 根据最后一次评论时间来决定是否显示评论者链接

已有 273 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!