Typecho 教程 - 非插件实现回复可见

忘心
2020-06-13 / 1 评论 / 2,831 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2023年03月29日,已超过189天没有更新,若内容或图片失效,请留言反馈。

前言

这个教程网上很多的,包括我也是从网上搬来的,但是网上的涉及文件太多,这里给大家推荐我修改的方法,希望能帮助到大家。
首先我们进入 / 网站根目录 /usr/themes/{主题名} ,然后按照下面的文件来修改。

post.php 文件

    //找到
    <?php $this->content(); ?>
    //修改成
    <?php echo parse_content($this->content,$this->cid,$this->remember('mail',true),$this->user->hasLogin()); ?>
</pre></code>
## functions.php 文件 ##
<pre><code>
    //找一处,添加下面的代码
    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",'<div class="reply2view">您需要<a href="/admin/login.php">登录</a>或者<a onclick="window.scrollTo(0, document.documentElement.clientHeight);">回复</a>才能显示此处隐藏内容。</div>',$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 文件

    <!-- 带有半透明效果的样式 -->
    <style>
    .reply2view {
        background-color:rgb(255,255,255,0.3);
        border-radius:5px;
        border:1px dashed #888888;
        padding:10px 10px 10px 40px;
        position:relative;
    }
    </style>

完成

忘心,为你要隐藏的内容
一定要把hide前面的@去掉,这里是为了不让他隐藏掉加的

[@hide]忘心[/hide]
3

评论 (1)

取消
  1. 头像
    2253
    Windows 10 · QQ Browser

    我不知道怎么样

    回复