wordpress的短码功能太强大了。通过短码我们可以自定义任何东西。以前我开发了一个关于Wordpress短码集成的插件“Wp shortcode – 免费短码插件”,就是采用短码集成各种常用短码。今天,突然看到微信公众号设置自动回复的时候突然有一个想法,能不能通过wordpress短码结合微信公众号的自动回复功能,实现吸粉功能呢。还真有,今天把这个功能集成到我的博客上了,发现一部分网友说也需要同样的功能,就整理了下相关的资料,做一个教程。希望对喜欢折腾的朋友有所帮助。

演示效果:

The WordPress Toolbox
Unlimited Downloads: 500,000+ WordPress Themes, Plugins, Templates & Design Assets

教程:用短码实现关注微信公众号才能查看指定内容[吸粉神器]

DOWNLOAD NOW

教程:用短码实现关注微信公众号才能查看指定内容[吸粉神器]

好了,大家看了效果演示,我们开始教程了:

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
		
此处内容已经被作者无情的隐藏,请输入验证码查看内容
请关注主题之家官方QQ公众号,回复关键字“关键字”,获取验证码。【注】用手机QQ扫描右侧二维码都可以关注主题之家官方QQ公众号。
教程:用短码实现关注微信公众号才能查看指定内容[吸粉神器]
', "" ); </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;}

教程结束。如果有不懂代码的。我作出了一个php文件。大家下载下来放在主题目录下,然后在functions.php引用该文件即可,并在主题目录下的style.css文件莫问加入步骤3的css即可。引用代码如下:

require get_stylesheet_directory() . '/ghz.php';

4、使用说明:

(1)公众号设置内容:(以QQ公众号为例)

教程:用短码实现关注微信公众号才能查看指定内容[吸粉神器]

(2)wordpress后台使用教程:通过后台编辑器插入短码即可,短码有两个关键值,keyword为你微信公众号设置的关键字回复的关键字,key代表当用户回复关键字时得到的回复验证码。如上图的,用户对公众号发消息“dux优化版”得到的验证码就是“299416”。短码的keyword设置成“dux优化版”,key设置成"299416"即可。

本教程所有代码下载:

此处内容已经被作者无情的隐藏,请输入验证码查看内容
请关注主题之家官方QQ公众号,回复关键字“教程”,获取验证码。【注】用手机QQ扫描右侧二维码都可以关注主题之家官方QQ公众号。
教程:用短码实现关注微信公众号才能查看指定内容[吸粉神器]

发表回复