Typecho部分文章内容的登陆可见代码实现方法
具体方法就是使用以下代码:
<?php
if($this->user->hasLogin()) {
$content = preg_replace('/<!--loginview start-->([\s\S]*?)<!--loginview end-->/i','$1',$this->content);
}
else{
$content = preg_replace('/<!--loginview start-->([\s\S]*?)<!--loginview end-->/i','<div style="text-align:center;border:1px dashed #FF9A9A;padding:8px;margin:10px auto;color:#FF6666;"></br></br>此处内容登陆后方可阅读,谢谢关注!</br></br></br></div>',$this->content);
}
echo $content
?>
替代index.php、post.php和archive.php
中的以下代码:
<?php $this->content(''); ?>
使用方法:写文章时在隐藏的内容前后添加以下代码:
<!--loginview start-->隐藏的内容<!--loginview end-->
另外,将本来在style.css中定义隐藏内容显示样式的代码结合到上面的代码中了,省去在style.css中增加样式。
大概样式如下:
广告声明:文内含有的对外跳转链接(包括不限于超链接、二维码、口令等形式),用于传递更多信息,节省甄选时间,结果仅供参考,Typecho.Wiki所有文章均包含本声明。