之前看见WP的博客,部分内容都带着阅读回复可见的功能。所以在网上找了很多的版本,所以这个也是从网上搬来的。这个方法已经测试过可行,分享给你们。来自: typecho wiki
进入 网站目录/usr/themes/正在使用主题 找到 post.php 打开
步骤一
在 post.php 找到 <?php $this->content(); ?> 替换成
1<?php
2$db = Typecho_Db::get();
3$sql = $db->select()->from('table.comments')
4 ->where('cid = ?',$this->cid)
5 ->where('mail = ?', $this->remember('mail',true))
6 ->limit(1);
7$result = $db->fetchAll($sql);
8if($this->user->hasLogin() || $result) {
9 $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view">$1</div>',$this->content);
10}
11else{
12 $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view">此处内容需要评论回复后方可阅读。</div>',$this->content);
13}
14echo $content
15?>
解决feed内容和缩略内容暴露
在 functions.php 中加入如下代码
1Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('moleft','one');
2Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('moleft','one');
3class moleft {
4 public static function one($con,$obj,$text)
5 {
6 $text = empty($text)?$con:$text;
7 if(!$obj->is('single')){
8 $text = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'此处内容已隐藏',$text);
9 }
10 return $text;
11 }
12}
就是用插件接口,在缩略内容输出之前,隐藏掉或者替换掉回复可见内容,同时使用if判断,来针对非single页面进行隐藏。
步骤三
在写文章需要隐藏部分内容时用以下写法(去掉@)
1[@hide]要隐藏的内容[/hide]
css代码参考,我在使用的