
现在WordPress博客博主指不定哪天就不更新关站,域名也不续费被域名注册商收回释放。
有很多域名就会被做小视频或者小图片的人购买解析到某站,指不定评论者的网站挂了,被搞成了有害人身心健康的网站呢。
而为了防范这种情况,同时也增强博客网站的互动性,可以根据评论者最后一次评论时间来决定是否显示评论者链接。
比如,评论者的最后一次评论时间距离当前时间超过了 10 天,就禁止显示评论者网站链接。
直接function.php贴上代码:
/**
* WordPress根据最后一次评论时间来决定是否显示评论者链接
* http://www.ilxtx.com/display-or-hide-comment-author-link-according-to-last-comment-date.html
*/
function lxtx_show_comment_author_link( $return , $author, $comment_ID ){
if ( !is_user_logged_in() ) { // 登录用户无鸭梨
date_default_timezone_set('PRC');
$limit_days = 10; // 天数,代表最后一次评论时间距离今天超过10天的话,则隐藏评论链接
$comment = get_comment( $comment_ID );
if ( !empty($comment->comment_author_email) ) {
$last_comment = get_comments(array(
'author_email' => $comment->comment_author_email,
'number' => '1',
'orderby' => 'comment_date',
'order' => 'DESC',
'status' => 'approve',
'type' => 'comment'
));
if ( (time() - strtotime($last_comment->comment_date)) > $limit_days*24*3600 ) {
$return = $author;
}
}else{
$return = $author;
}
}
return $return;
}
add_filter('get_comment_author_link','lxtx_show_comment_author_link', 10, 3);当然,本方法仅适合使用 the_author_link()来输出评论者昵称的主题,一般来讲,标准主题都会使用这个函数。
未经允许不得转载:主机格调 » WordPress根据最后一次评论时间判断是否显示评论者链接
主机格调




这个感觉很不错,可以试试。
是的,可以增加访问互动性