第一步,我们要在模板中的module.php中加入这个代码: <?php
include(TEMPLATE_PATH . 'function.php');
function login_to_view($content){
if (preg_match_all('/<!--loginview start-->([\s\S]*?)<!--loginview end-->/i', $content, $hide_words)){
if( ISLOGIN ){
$content = str_replace($hide_words[0], $hide_words[1], $content);
}else{
$hide_notice = '<div style="text-align:center;border:1px dashed #FF9A9A;padding:8px;margin:10px auto;color:#FF6666;">您必须先<a href="'.BLOG_URL.'admin">登录</a>才能查看隐藏内容</div>';
$content = str_replace($hide_words[0], $hide_notice, $content);
}
}
return $content;
}
?>
第二步,在模板中的echo_log.php中找到$log_content改成login_to_view($log_content); 这样就可以啦,当我们在写文章时需要引用,只要切换到html模式,加入要隐藏的内容,就可以了。