Typecho文章内容回复可见功能代码

No Reply , Posted in 代码 on April 14, 2014

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

替代

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

使用方法

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

CSS参考

.reply2view {
    background:#f8f8f8;
    padding:10px 10px 10px 40px;
    position:relative
}
.reply2view i {
    display:block;
    font-size:20px;
    height:20px;
    left:10px;
    line-height:20px;
    position:absolute;
    top:15px
}

标签: 回复可见