WordPress 文章隐藏内容需要关注微信公众号可见
摘要:利用WordPress 短代码将文章中的部分内容隐藏,通过注微信公众号自动回复获取查看验证码。放点吸引人的玩意,可以增加公众号的粉丝。
将以下下代码放在主题的 functions.php 中;
// WordPress文章部分内容关注微信公众号后可见
function wechat_secret_content($atts, $content=null){
extract(shortcode_atts(array('key'=>null,'keyword'=>null), $atts));
// 管理员登录直接显示隐藏内容
if ( current_user_can('level_10') ) {
return '<div class="secret-password">'.do_shortcode( $content ).'</div>';
}
// 输入正确验证码显示隐藏内容
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://tva3.sinaimg.cn/large/007Ey3w0gy1gbkqferx3kj30760763yz.jpg" width="150" height="150" alt="日草"><div class="post-secret"><i class="zm zm-kucunjinggao"></i><b>下载链接</b></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">扫描右侧二维码“<span>日草君</span>” 或在微信搜索“<span>Ricaoapi</span>”并关注;</div>
<div class="details">每篇文章的验证码都不相同,只需关注一次即可;回复“<span>'.get_the_ID().'</span>”获取本文的验证码;</div>
</div>';
}
}
add_shortcode('password', 'wechat_secret_content');
美化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] {
width: 18%;
color: #9ba1a8;
padding: 6px;
background-color: #f6f6f6;
border: 1px solid #e4e6e8;
font-size: 12px;
-moz-transition: border .35s linear,color .35s linear,background-color .35s linear;
-webkit-transition: border .35s linear,color .35s linear,background-color .35s linear;
-o-transition: border .35s linear,color .35s linear,background-color .35s linear;
transition: border .35s linear,color .35s linear,background-color .35s 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;
}
使用方法
使用时请将 { } 替换为 [ ]
{password key=密码}加密的内容{/password}
效果展示
本文系作者 @Ricaojun 原创发布在 日草君。未经许可,禁止转载。