typecho博客纯代码如何实现回复可见功能

搬瓦工机场JMS

因为一般首页很少有全文输出的,而且一般隐藏内容都放在文章后面,所以就不需要处理首页的输出内容了。

直接处理 post.php 就可以了,使用下面的代码

<?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 
?>

替换模板 post.php 中的

<?php $this->content(); ?>

使用方法, 在写文章需要隐藏部分内容时用以下写法 (去掉 @)

[@hide]要隐藏的内容[/hide]

css 参考样式

.reply2view {
    background:#f8f8f8;
    padding:10px 10px 10px 40px;
    positiON:relative
}

本文代码为了更好地适应各种模板,对原代码稍加了点删改。

未经允许不得转载:搬瓦工VPS_美国VPS » typecho博客纯代码如何实现回复可见功能

赞 (0) 打赏

相关推荐

    暂无内容!

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏