记录学习与后端知识并分享学习代码过程(会飞的鱼Blog)

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

会飞的鱼 0 1579 2017年9月26日

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

操作步骤:

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

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文件中找到代码:

<?php echo $log_content; ?>
替换为:

<?php echo slyc($log_content); ?>
3、在编辑文章的时候,切换到HTML模式,在要隐藏的内容前后分别添加代码,如:

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

效果如下:

Image

本文由 @会飞的鱼 于 2017-9-26 发布在 会飞的鱼Blog,如无特别说明,本博文章均为原创,转载请保留出处。

网友评论

    暂无评论

会飞的鱼 V

一条会飞的鱼!

745 文章
7274 评论
1070 万 阅读
8年 博龄
最新文章
最新评论
嘻嘻嘻
1个月前 (2024-03-19)

ThinkPHP实现用户注册、登录模块

标签

会飞的鱼 在线咨询

在线时间:9:00-22:00
周六、周日:14:00-22:00