纯代码实现WordPress文章部分内容关注微信公众号后可见 您所在的位置:网站首页 wordpress文章页底部公众号 纯代码实现WordPress文章部分内容关注微信公众号后可见

纯代码实现WordPress文章部分内容关注微信公众号后可见

2024-02-16 07:42| 来源: 网络整理| 查看: 265

前言

最新有小伙伴问我一个问题,像辉哥博客有些文章是用的关注微信公众号并回复指定内容后获取验证码才能查看文章的部分内容是怎么实现的,今天辉哥就教你纯代码实现WordPress文章部分内容关注微信公众号后可见

教程开始

首先打开你所使用的主题文件的function.php,在底部加上下面这段代码,请将你的微信公众号二维码图片路径设置好

/** * WordPress文章部分内容关注微信公众号后可见 */ function lxtx_secret_content($atts, $content=null){ extract(shortcode_atts(array('key'=>null,'keyword'=>null), $atts)); if(isset($_POST['secret_key']) && $_POST['secret_key']==$key){ return ''.$content.''; } else if($_POST['secret_key']!=$key&&$_POST['secret_key']!=""){ return '验证码输入错误,请重新输入!验证码:请关注“辉哥博客”官方微信公众号,回复关键字“'.$keyword.'”,获取验证码。'; }else{ return '此处内容已经隐藏,请输入验证码查看内容!验证码:请关注“辉哥博客”官方微信公众号,回复关键字“'.$keyword.'”,获取验证码。'; } } add_shortcode('gzh2v', 'lxtx_secret_content');

2. 将下面的代码加入你的style.css中,即可实现

 

.post_hide_box, .secret-password{ background: none repeat scroll 0 0 #fcffff; border: 1px dashed #24b4f0; color: #123456; padding: 10px; border-radius: 9px; margin: 18px 0px; overflow:hidden; clear:both; } .post_hide_box .post-secret{ font-size: 18px; line-height:20px; color:#f0503c; margin:5px; } .post_hide_box form{ margin:15px 5px;} .post_hide_box form span{ font-size:18px; font-weight:bold;} .post_hide_box .erweima{ margin: 15px;} .post_hide_box input[type=password]{ color: #00a0f0; padding: 5px; background-color: #fff; border: 1px solid #24b4f0; border-radius: 5px; font-size: 12px; margin: 6px 7px 6px 0px; -moz-transition: border .25s linear,color .25s linear,background-color .25s linear; -webkit-transition: border .25s linear,color .25s linear,background-color .25s linear; -o-transition: border .25s linear,color .25s linear,background-color .25s linear; transition: border .25s linear,color .25s linear,background-color .25s linear; } .post_hide_box input[type=submit] { background: #24b4f0; border: none; padding: 5px; width: 88px; color: #fff; border-radius: 5px; font-size: 16px; font-weight:bold; } .details{ color:#123456; font-size: 16px; line-height: 30px; margin: 5px; padding: 3px; } .post_hide_box .details span{color:#e74c3c;}

 

使用

在你的文章编辑器中加入该短代码即可

【gzh2v keyword="关键字" key="验证码"】【/gzh2v】 说明:将【】换成[]

​​​​​​​

如果复制的代码出现不能用的情况,可以点击下方链接查看源文章下载

源文链接:https://www.haah.net/archives/6545.html

 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有