太云互联

Typecho实现回复查看全文

以下文件都在当前主题目录下修改,文件路径为:网站根目录/usr/themes/主题名。


修改post.php文件

找到content(); ?>

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

替换为

<?php echo parse_content($this->content,$this->cid,$this->remember('mail',true),$this->user->hasLogin()); ?>

在函数 functions.php 文件
在最后位置添加一下代码:

/**
* 回复可见所需功能代码*
* @access public
* @param string $content 文章内容
* @return string
*/
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",'<div class="reply2view">$1</div>',$content);
    }
    else{
        $content = preg_replace("/\[hide\](.*?)\[\/hide\]/sm",'<div class="reply2view">此处内容回复可见,请先<a href="#respond-post-'. $cid .'">回复</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;
    }
}

添加样式
在样式表:style.css在最后面添加以下代码:
<!-- 在head标签中添加回复可见的样式 -->
<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]要隐藏的内容[/hide]

[/hide]


WP应该也可以吧

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »