其实这是一个比较鸡肋的功能,而且其实很好找出来密码,firefox这类浏览器,右键显示源代码,就能找到隐藏内容,甚至是通过这种方式设置的密码。我就通过这种方法扒过别人网站的资源。
不过聊胜于无,重在折腾。主要是https://anyu.tv这个网站上,准备放一些真正的干货,有些干货,得来不易,不想就这么完全公开。之前在哪里看过一篇文章,说千万不要完全免费的分享出去,太容易得到的不会珍惜,这是人的共性,设置一点点障碍,用户更珍惜所得,也更容易记住这个站点。所以,未来干货内容都要设置一点点障碍,引流也好,吸粉也好,多少增加点儿网站流量。
网站不是主页,纯属爱好,折腾太多,flytofilm.com被自己折腾的半年百度不收录,今天早上突然发现收录恢复了,虽然并没有什么卵用,还是很开心的。
好了,闲话到这里,接下来分享代码;
一、在functions.php里增加如下代码:
- /*部分内容输入密码可见(短代码*/
- 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="post-password-form" action="'.get_permalink().'" method="post" name="e-secret"><p><label for="pwbox-142">输入密码查看加密内容: <input type="password" name="e_secret_key" size="20" /></label> <input type="submit" class="euc-y-s" value="确定" /></p>
- </form>
- ';
- }
- }
- add_shortcode('secret','e_secret');
二、在CSS里添加:
- /*文章密码可见样式e-secret*/
- .e-secret {
- margin: 20px 0;
- padding: 20px;
- background: #f8f8f8;
- overflow: auto;
- }
- .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:#FF0016;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:#CE0416;}
- 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
三、添加文本编辑器按钮
为了方便编辑文章时候运用,需要添加一个按钮。参看:
wordpress给后台文本编辑器增加按钮
请登录以参与评论
现在登录