libo 发表于 2018-10-7 17:39:17

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\]/sm",'<div class="reply2view">$1</div>',$this->content);
}
else{
    $content = preg_replace("/\(.*?)\[\/hide\]/sm",'<div class="reply2view">此处内容需要评论回复后方可阅读。</div>',$this->content);
}
echo $content
?>


替换模板post.php中的

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

使用方法,在写文章需要隐藏部分内容时用以下写法(去掉@)


css参考样式

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

页: [1]
查看完整版本: typecho非插件实现回复可见功能