完美实现回复可见功能,避免缩略内容和Feed里出现回复可见内容。

步骤一:

post.php中的<@?php $this->content(); ?>(去掉@)换成下方内容:

select()->from('table.comments')
    ->where('cid = ?',$this->cid)
    ->where('mail = ?', $this->remember('mail',true))
    ->where('status = ?', 'approved')
//只有通过审核的评论才能看回复可见内容
    ->limit(1);
$result = $db->fetchAll($sql);
if($this->user->hasLogin() || $result) {
    $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'$1',$this->content);
}
else{
    $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'此处内容需要评论回复后方可阅读。',$this->content);
}
echo $content 
?>

步骤二:

解决缩略和Feed暴露问题

functions.php中插入以下代码

Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('myyodux','one');
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('myyodux','one');
class myyodux {
    public static function one($con,$obj,$text)
    {
      $text = empty($text)?$con:$text;
      if(!$obj->is('single')){
      $text = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'',$text);
      }
      
               return $text;
}
}

用插件接口,在缩略内容输出之前,隐藏掉或替换掉回复可见内容,同时使用if判断,来针对非single页面进行隐藏。

步骤三:

文章中需要隐藏部分内容时使用以下代码

[hide]要隐藏的内容[/hide]
© 版权声明
评论 抢沙发
头像
请认真填写,胡乱按键盘或文字不通不会审核通过!
提交
头像

昵称

取消
昵称表情图片