|
因为一般首页很少有全文输出的,而且一般隐藏内容都放在文章后面,所以就不需要处理首页的输出内容了。
直接处理post.php就可以了,使用下面的代码
[pre]
<?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
?>
[/pre]
替换模板post.php中的
[pre]
<?php $this->content(); ?>
[/pre]
使用方法,在写文章需要隐藏部分内容时用以下写法(去掉@)
css参考样式
[pre]
.reply2view {
background:#f8f8f8;
padding:10px 10px 10px 40px;
position:relative
}
[/pre]
|
|