WordPress如何实现关注微信公众号查看文章部分内容?

无评论

作者照片

By 霜天

最近浏览一些网站的时候发现很多站长在文章页会加上关注公众号才能查看到文章中的隐藏内容,也有用户咨询过,小编就从网上收集了一下方法告诉大家WordPress如何实现关注微信公众号查看文章部分内容?

将以下代码放入functions.php中

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

function wphome_secret_content($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://www.wpzt.net/%E6%94%B9%E4%B8%BA%E4%BA%8C%E7%BB%B4%E7%A0%81%E5%9B%BE%E7%89%87%E7%9A%84%E7%BD%91%E5%9D%80\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” 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(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wechatmp\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wphome_secret_content\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’);

将以下代码放到你主题的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;}

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

// 后台文本编辑框中添加公众号隐藏简码按钮

function wphome_wpsites_add_wechatmp_quicktags() {

if (wp_script_is(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’quicktags\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’)){

?>

<script type=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”text/javascript\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”>

QTags.addButton( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wechatmp\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ 公众号隐藏\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n[wechatmp keyword=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”关键字\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” key=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”验证码\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”]隐藏内容[/wechatmp]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” );

</script>

<?php

}

}

add_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’admin_print_footer_scripts\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wphome_wpsites_add_wechatmp_quicktags\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );

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

[wechatmp keyword=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”关键字\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\” key=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”验证码\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”]隐藏内容[/wechatmp]

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

发表评论