搜索
查看: 5347|回复: 0

typecho非插件实现回复可见功能

[复制链接]

330

主题

177

回帖

1071

积分

vip用户

积分
1071

注册会员活跃会员热心会员

QQ
发表于 2018-10-7 17:39:17 来自手机 | 显示全部楼层 |阅读模式
因为一般首页很少有全文输出的,而且一般隐藏内容都放在文章后面,所以就不需要处理首页的输出内容了。

直接处理post.php就可以了,使用下面的代码
[pre]
<?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
?>
[/pre]

替换模板post.php中的
[pre]
<?php $this->content(); ?>
[/pre]
使用方法,在写文章需要隐藏部分内容时用以下写法(去掉@)


css参考样式
[pre]
.reply2view {
    background:#f8f8f8;
    padding:10px 10px 10px 40px;
    position:relative
}
[/pre]
17-39-05-u=2830788171,1031053283&amp;fm=11&amp;gp=0.jpg
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表