之前看见WP的博客,部分内容都带着阅读回复可见的功能。所以在网上找了很多的版本,所以这个也是从网上搬来的。这个方法已经测试过可行,分享给你们。来自: typecho wiki
进入 网站目录/usr/themes/正在使用主题
找到 post.php
打开
步骤一
在 post.php
找到 <?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
?>
解决feed内容和缩略内容暴露
在 functions.php
中加入如下代码
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('moleft','one');
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('moleft','one');
class moleft {
public static function one($con,$obj,$text)
{
$text = empty($text)?$con:$text;
if(!$obj->is('single')){
$text = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'此处内容已隐藏',$text);
}
return $text;
}
}
就是用插件接口,在缩略内容输出之前,隐藏掉或者替换掉回复可见内容,同时使用if判断,来针对非single页面进行隐藏。
步骤三
在写文章需要隐藏部分内容时用以下写法(去掉@)
[@hide]要隐藏的内容[/hide]
css代码参考,我在使用的
.reply2view {
background-color: rgba(0,0,0,.075);
border-radius: 5px;
border: 1px dashed #888888;
position: relative;
text-align: center;
padding: 10px 20px;
}
这个不错,不要插件,又不影响速度。