Typecho非插件实现回复可见功能

首页很少有全文输出的,而且一般隐藏内容都放在文章后面,所以就不需要处理首页的输出内容了,修改post.php就可以了

<?php
$db = Typecho_Db::get();
$sql = $db->select()->from('table.comments')
    ->where('cid = ?',$this->cid)
    ->where('mail = ?', $this->remember('mail',true))
    ->limit(1);
$result = $db->fetchAll($sql);
if($this->user->hasLogin() || $result) {
    $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view">$1</div>',$this->content);
}
else{
    $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view">此处内容需要评论回复后方可阅读。</div>',$this->content);
}
echo $content 
?>

使用上面的代码替换模板post.php中的

<?php $this->content(); ?>

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;
}
}

使用方法:在写文章需要隐藏部分内容时用以下写法

[hide]要隐藏的内容[/hide]

css参考样式

.reply2view {
    background:#f8f8f8;
    padding:10px 10px 10px 40px;
    position:relative
}

游戏

怎样在Nintendo Switch上进行游戏共享

2020-6-15 21:06:06

建站

web.config实现整站301永久重定向

2019-1-7 9:39:19

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索