WordPress文章内容隐藏输入密码后可见

WordPress文章内容隐藏输入密码后可见

作者 : 资源客 发布时间: 2019-12-15

前两天看到一位小伙伴需要这个功能,现在将代码分享给大家。利用的是 wordpress 的短代码功能,做得比较简单,没有使用 AJAX 加载。
将一下代码放入主题的函数模板(functions.php)

/* Name: 部分内容输入密码可见(短代码)
*/
function e_secret($atts, $content=null){
extract(shortcode_atts(array('key'=>null), $atts));
if(isset($_POST['e_secret_key']) && $_POST['e_secret_key']==$key){
return '
<div class="e-secret">'.$content.'</div>
';
}
else{
return '
<form class="e-secret" action="'.get_permalink().'" method="post" name="e-secret"><label>输入密码查看加密内容:</label><input type="password" name="e_secret_key" class="euc-y-i" maxlength="50"><input type="submit" class="euc-y-s" value="确定">
<div class="euc-clear"></div>
</form>
';
}
}
add_shortcode('secret','e_secret');

样式代码,下面附上,细节需要自己修改。

/*e-secret*/
.e-secret {
margin: 20px 0;
padding: 20px;
background: #f8f8f8;
}
.e-secret input.euc-y-i[type="password"] {
float: left;
background: #fff;
width: 100%;
line-height: 36px;
margin-top: 5px;
border-radius: 3px;
}
.e-secret input.euc-y-s[type="submit"] {
float: right;
margin-top: -47px;
width: 30%;
margin-right: 1px;
border-radius: 0 3px 3px 0;
}
input.euc-y-s[type="submit"]{background-color:#3498db;color:#fff;font-size:21px;box-shadow:none;-webkit-transition: .4s;-moz-transition: .4s;-o-transition: .4s;transition:.4s;-webkit-backface-visibility:hidden;position:relative;cursor:pointer;padding: 13px 20px;text-align: center;border-radius: 50px;-webkit-box-shadow: none; -moz-box-shadow: none; box-shadow: none;border: 0;height: auto;outline: medium;line-height: 20px;margin: 0;}
input.euc-y-s[type="submit"]:hover{background-color:#5dade2;}
input.euc-y-i[type="text"],input.euc-y-i[type="password"]{border:1px solid #F2EFEF;color:#777;display:block;background: #FCFCFC;font-size:18px;transition:all .5s ease 0;outline:0;box-sizing:border-box;-webkit-border-radius:25px;-moz-border-radius:25px;border-radius:25px;padding:5px 16px; margin: 0;height: auto;line-height: 30px;}
input.euc-y-i[type="text"]:hover,input.euc-y-i[type="password"]:hover{border:1px solid #56b4ef;box-shadow:0 0 4px #56b4ef;}

前端样式可以参考我的,也可以根据自己的主题自己设计。在文章中使用短代码 secret 调用,示例:

[secret key="密码"]
加密内容
[/secret]

 

http://xzh.i3geek.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,请不要用于商业用途及非法用途,否则后果自负!
3. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"qq301.com",如遇到无法解压的请联系管理员!
资源客是一个优秀的分享资源站,本站资源均为各位友友分享而来,特殊原创会标明如有侵犯版权等可联系删除

资源客 » WordPress文章内容隐藏输入密码后可见