Typecho实现文章回复可见效果代码

发布时间:

我们经常遇到一些个人网站提供的重要的文件下载、主题下载等文件需要用户回复可见。这些功能到底是如何实现的呢?今天需要分享的是在Typecho程序中如何实现回复才可见的效果。

Typecho实现文章回复可见效果代码

找到文章展示页面模板

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

替换成:

<?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
?>

使用方法

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