WordPress 文章部分内容关注微信公众号后可见

2017-06-28 06:36 3,991 52 条评论 龙笑天下
Dragon主题购买

WordPress 文章部分内容关注微信公众号后可见

很早之前就知道有这么一个功能,只有关注公众号并回复关键字获取验证码后,才能查看到文章中的隐藏内容。但一直没想好怎么用,今天就把它拿起来使用下吧~

当然,这个功能是可以通过插件来实现的,但本人是喜欢代码版的;所以直接上代码了!

1 核心代码

本站 Dragon 主题已经自带集成了这个功能,更加好的实现,更加利于新手,(已隐藏核心代码)展示效果如下:

此处内容已经被作者无情的隐藏,请输入验证码查看内容
验证码:
请关注龙笑天下官方微信公众号,回复关键字“2483”,获取验证码。
注:用手机微信扫描右侧二维码或微信搜索公众号“龙笑天下”即可关注哦!

注意修改代码中的相关内容!

2 前端 CSS 样式

将以下代码放到你主题的 style.css 文件中:

.post_hide_box, .secret-password{background: none repeat scroll 0 0 #efe;border-left: 5px solid #e74c3c;color: #555;padding: 10px 0 10px 10px;border-radius: 5px;margin-bottom: 15px;overflow:hidden; clear:both;}
.post_hide_box .post-secret{font-size: 18px; line-height:20px; color:#e74c3c; margin:5px;}
.post_hide_box form{ margin:15px 0;}
.post_hide_box form span{ font-size:18px; font-weight:700;}
.post_hide_box .erweima{ margin-left:20px; margin-right:16px;}
.post_hide_box input[type=password]{ color: #9ba1a8; padding: 6px; background-color: #f6f6f6; border: 1px solid #e4e6e8; font-size: 12px;-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: #F88C00; border: none; border: 2px solid;border-color: #F88C00; border-left: none; border-top: none; padding: 0px;width: 100px; height: 38px; color: #fff; outline: 0;border-radius: 0 0 2px 0; font-size: 16px;}
.post_hide_box .details span{color:#e74c3c;}

3 集成短代码

为了方便使用,在后台文本编辑器中集成该短代码。将以下代码放入 functions.php 中即可:

// 后台文本编辑框中添加公众号隐藏简码按钮
function lxtx_wpsites_add_gzh_quicktags() {
    if (wp_script_is('quicktags')){
?>
    <script type="text/javascript">
    QTags.addButton( 'gzh2v', ' 公众号隐藏', '\n[gzh2v keyword="关键字" key="验证码"]隐藏内容[/gzh2v]', "" );
    </script>
<?php
    }
}
add_action( 'admin_print_footer_scripts', 'lxtx_wpsites_add_gzh_quicktags' );

4 使用方法

4.1 在文章中使用短代码

插入以下简码,修改相关内容即可:

[gzh2v keyword="关键字" key="验证码"]隐藏内容[/gzh2v]

4.2 微信公众号

这里以微信公众号为例(QQ 公众号应该也是这样),在微信公众号的“自动回复-关键字自动回复”中设置好关键字(对应上面代码中的 keyword)及验证码(对应上面代码中的 key)。

比如本文中,keyword 为 2483,key 为???自行关注后查看哈~

5 延伸

其实本文是跟常见的“文章部分内容回复后看见”或“文章部分内容登录后可见”的代码原理一致,只是结合了一下公众号而已。大家可以动动手集成到自己的主题哈!

搞这个公众号把我的自定义菜单搞没了,哭晕了...未认证的公众号没有自定义菜单的权限~啊~啊~啊~~~

「点点赞赏,手留余香」

还没有人赞赏,快来当第一个赞赏的人吧!

声明:本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

2017-06-05

2017-07-14

发表评论

表情 格式 贴图 链接 私密 签到
Dragon主题购买阿里云特价云服务器1核2G低至86元,N4共享型服务器3年仅需799元腾讯云特价云服务器1核2G 88元/年 2核4G3M688元/3年,更有千元代金券礼包免费领!
评论
正在努力加载中...
扫一扫二维码分享
×
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies. Learn more