Typecho主题插件站
每一个作品都值得被记录

Typecho 非插件实现回复可见功能

Typecho爱好者开发日志 • 2787次浏览 • 发布 2018-05-17 • 更新 2018-05-17
极致加速的V2Ray 助您畅享全球网络 & 搬瓦工VPS最新优惠码

Typecho 内容评论可见功能可能部分博主会用到,今天TypechoWiki就给大家带来了教程,通常首页很少有全文输出的,而且一般隐藏内容都放在文章后面,所以就不需要处理首页的输出内容了,直接处理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 {
    display: block;
    background: #e85a4f;
    padding: 10px;
    border: 2px dashed #8a352f;
    color: #fff;
    max-width: 100%;
    overflow: hidden;
}

改样式参考自我的博客文章:简单操作告诉你如何注册拥有一个自己的美国 APP Store 账号?(有福利)

本文检索关键词:开发日志
厂商投放
添加新评论 »