之前转载过这么一篇文章《typecho非插件完成复兴可见功用》,能够完成复兴可见功用,然则有个问题,在文章列表页展现文章缩略内容时,假如复兴可见内容刚好在缩略内容的位置上时,就会暴露出来,同时Feed内里也会暴露这个问题,那末怎样处理呢,下面请看怎样几近圆满的完成复兴可见功用:
步骤一
就是《typecho非插件完成复兴可见功用》内里的内容
将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)) ->where('status = ?', 'approved')//只要经由过程考核的批评才能看复兴可见内容 ->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('myyodux','one');Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('myyodux','one');class myyodux { 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:#f8f8f8; padding:10px 10px 10px 40px; position:relative}心里话
在写yodu模板的时刻,由于网友须要,我就找了教程把复兴可见功用加上了,当时也是晓得这个东西的bug,然则本身不会修,近来写了个typecho的搜刮插件,看了一些typecho的插件接口和源码,发现用插件接口很好的就可以处理了,于是乎水文一下,希望能协助到一些人。

评论列表