Typecho 不使用插件实现回复可见

 2024-02-24    1854  

进入   网站目录 /usr/themes/ 主题   找到  post.php  打开

步骤一

在  post.php  找到  <?php $this->content(); ?>  替换成

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

解决 feed 内容和缩略内容暴露

在  functions.php  中加入如下代码

html 代码:

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;
    }
}

就是用 插件 接口,在缩略内容输出之前,隐藏掉或者替换掉回复可见内容,同时使用 if 判断,来针对非 single 页面进行隐藏。

步骤三

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

html 代码:

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

css 代码参考,我在使用的

css 代码:

.reply2view {    background-color: rgba(0,0,0,.075);
    border-radius: 5px;
    border: 1px dashed #888888;
    position: relative;
    text-align: center;
    padding: 10px 20px;}
打赏 支付宝打赏 微信打赏
  •  标签:  

发表评论:

原文链接:http://16dajie.com/shibei/77.html

=========================================

http://16dajie.com/ 为 “首页” 唯一官方服务平台,请勿相信其他任何渠道。