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

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

步骤一

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

<?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 中加入如下代码

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页面进行隐藏。

步骤三

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

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

css代码参考,我在使用的

.reply2view {
    background-color: rgba(0,0,0,.075);
    border-radius: 5px;
    border: 1px dashed #888888;
    position: relative;
    text-align: center;
    padding: 10px 20px;
}
发布于福建
温馨提示:本文最后更新于2023-04-18 13:00:29,若内容有错误或图片已失效,请在下方留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。本站使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
THE END
喜欢就支持一下吧
点赞14赞赏 分享
评论 共3条

请登录后发表评论

    • 头像Sirit0
    • 头像明月登楼0