前言
这个教程网上很多的,包括我也是从网上搬来的,但是网上的涉及文件太多,这里给大家推荐我修改的方法,希望能帮助到大家。
首先我们进入 / 网站根目录 /usr/themes/{主题名} ,然后按照下面的文件来修改。
post.php 文件
//找到
content(); ?>
//修改成
content,$this->cid,$this->remember('mail',true),$this->user->hasLogin()); ?>
functions.php 文件
//找一处,添加下面的代码
function parse_content($content,$cid,$mail,$login){
$db = Typecho_Db::get();
$sql = $db->select()->from('table.comments')
->where('cid = ?',$cid)
->where('mail = ?', $mail)
->where('status = ?', 'approved')
->limit(1);
$result = $db->fetchAll($sql);
if($login || $result) {
$content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'$1',$content);
}
else{
$content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'',$content);
}
return $content;
}
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;
}
}
header.php 文件
完成
忘心,为你要隐藏的内容
一定要把hide前面的@去掉,这里是为了不让他隐藏掉加的
[@hide]忘心[/hide]
评论 (0)