短码实现关注微信公众号才能查看指定内容

    wordpress的短码功能太强大了。通过短码我们可以自定义任何东西,今天,突然看到微信公众号设置自动回复的时候突然有一个想法,能不能通过 wordpress短码结合微信公众号的自动回复功能,实现吸粉功能呢。还真有,今天把这个功能集成到我的博客上了,发现一部分网友说也需要同样的功能, 就整理了下相关的资料,做一个教程。希望对喜欢折腾的朋友有所帮助。
    1、我们采用的原理就是wordpress的密码隐藏功能,我们用短码将其进行适当扩展。短码代码添加主题目录下的functions.php文件最后,到具体的短码代码如下:

    // 加密内容
    function secret($atts, $content=null){
    extract(shortcode_atts(array('key'=>null,'keyword'=>null), $atts));
    if(isset($_POST['secret_key']) && $_POST['secret_key']==$key){
    	return '<div class="secret-password">'.$content.'</div>';
    	} else {
    		return '
    		<div class="post_hide_box">
    		<img class="erweima" align="right" src="https://dn-iesa.qbox.me/qrcode.png" width="150" height="150" alt=""><div class="post-secret"><i class="fa fa-exclamation-circle"></i>此处内容已经被作者无情的隐藏,请输入验证码查看内容</div>	
    		<form action="'.get_permalink().'" method="post">	
    				<span>验证码:</span><input id="pwbox" type="password" size="20" name="secret_key">
    				<a class="a2" href="javascript:;"><input type="submit" value="提交" name="Submit"></a>
    			
    		</form>
    		<div class="details">请关注官方QQ公众号,回复关键字“<span>'.$keyword.'</span>”,获取验证码。【注】用手机QQ扫描右侧二维码都可以关注官方QQ公众号。</div>
    			</div>';
    	}
    }
    add_shortcode('ghide', 'secret');
    

    2、有了短码,我们就可以使用了,但为了方便编辑,我们需要在后台加入编辑按钮。同样的方法,在代码添加主题目录下的functions.php文件最后:

    //编辑按钮
    function wpsites_add_gzh_quicktags() {
        if (wp_script_is('quicktags')){
    ?>
        <script type="text/javascript">
        QTags.addButton( 'ghide', ' 公众号隐藏', '\n[ghide keyword="关键字" key="验证码"]隐藏内容[/ghide]', "" );
        </script>
    <?php
        }
    }
    add_action( 'admin_print_footer_scripts', 'wpsites_add_gzh_quicktags' );
    

    3、有了代码。下面就是定义样式了。这里是你可以根据你自己的需要进行订制,我这里给大家一个演示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;}
    

    4、《1》最后在微信公众平台设置自动回复规则与关键词,《2》wordpress后台使用教程:通过后台编辑器插入短码即可,短码有两个关键 值,keyword为你微信公众号设置的关键字回复的关键字,key代表当用户回复关键字时得到的回复验证码。如上图的,用户对公众号发消息“某某主题” 得到的验证码就是“299416”。短码的keyword设置成“某某主题”,key设置成”299416″即可。

    此文为转载文章

    Responses

    您的电子邮箱地址不会被公开。 必填项已用*标注

    Up Next:

    基于bootstrap的单栏响应式主题:simple

    基于bootstrap的单栏响应式主题:simple