加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

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

发布时间:2020-12-14 14:29:42 所属栏目:wordpress 来源:网络整理
导读:由站长 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。 已经好久没有更新文章了,前段时间丢了 1 个月的数据也有点打击了更新的动力(貌似经常丢数据)丢的文章也没打算找回了。 前两天在贴吧看到一位小伙伴

以下代码由PHP站长网 52php.cn收集自互联网现在PHP站长网小编把它分享给大家,仅供参考

已经好久没有更新文章了,前段时间丢了 1 个月的数据也有点打击了更新的动力(貌似经常丢数据)丢的文章也没打算找回了。


前两天在贴吧看到一位小伙伴需要这个功能,现在将代码分享给大家。利用的是 wordpress 的短代码功能,做得比较简单,没有使用 AJAX 加载。


将一下代码放入主题的函数模板(functions.php)


/* Name: 部分内容输入密码可见(短代码)


* 作者:E 享乐(www.exiang2.com)


*/


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]

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读