关注迷你日志公众号

因为一般首页很少有全文输出的,而且一般隐藏内容都放在文章后面,所以就不需要处理首页的输出内容了。

直接处理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();?>

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

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

CSS参考样式

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

代码出自typecho论坛,本文代码为了更好地适应各种模板,对原代码稍加了点删改。

转自:《typecho非插件实现评论回复可见》

扫码了解详情