我们经常遇到一些个人网站提供的重要的文件下载、主题下载等文件需要用户回复可见。这些功能到底是如何实现的呢?在之前WordPress相关的功能上有过介绍(WordPress利用easy2hide插件实现评论内容可见模式),今天老蒋需要分享的是在Typecho程序中如何实现回复才可见的效果?
第一、找到文章展示页面模板


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

我们找到文章展示页面模板上面代码,然后替换成:

<?php
$db = Typecho_Db::get();<br> $sql = $db->select()->from('table.comments')<br> ->where('cid = ?',$this->cid)
->where('mail = ?', $this->remember('mail',true))<br> ->limit(1);<br> $result = $db->fetchAll($sql);
if($this->user->hasLogin() || $result) {
$content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view">$1
',$this->content);<br> }<br> else{<br> $content = preg_replace("/[hide](.*?)[/hide]/sm",'
此处内容需要评论回复后方可阅读。
',$this->content);<br> }<br> echo $content
?>

第二、如何使用

[hide]需要隐藏的内容部分丢到这里[/hide]

如果我们正常发表内容不要做任何操作,如果我们需要隐藏内容的话,就根据上面方法用标签隐藏。
第三、修改样式

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

然后可以根据实际主题配色需要修改样式。


扫描二维码,在手机上阅读!