Emlog实现隐藏文章内容登陆后可见的方法

Emlog教程 2842

一些开放会员注册的网站为了提高网站注册量,通常的做法会把网站文章内容的重要部分隐藏,用户登陆后才可以看得见,而使用emlog程序的用户想实现类似功能,可能通过下面的代码可以实现。

操作步骤:

1、在当前使用主题的module.php文件添加以下代码:

1
2
3
4
5
6
7
8
9
10
11
function slyc($content){
	if(preg_match_all('/<yc\>([\s\S]*?)<\/yc\>/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;
}

2、在主题的echo_log.php文件中找到代码:

1
<?php echo $log_content; ?>

替换为:

1
<?php echo slyc($log_content); ?>

3、在编辑文章的时候,切换到HTML模式,在要隐藏的内容前后分别添加代码<yc></yc>,如:

1
2
3
<yc>
此处是要隐藏的内容
</yc>

效果如下:

Emlog实现隐藏文章内容登陆后可见的方法

精品推荐: