我们经常看到有些个人网站内容需要输入密码才可见,如果是整篇文章加密模式都还简单,我们在发布文章"公开度"选项中可以选择设置加密且设置密码。但是,如果我们看到有些文章部分可见,部分是需要密码才可以看到的,那这样的样式是如何实现的呢?

老蒋在"WordPress利用easy2hide插件实现评论内容可见模式"文章中可以看到,有分享过使用插件实现评论后可见的模式,直接用插件。当然,如果对于内容部分加密肯定也有插件。这里整理到一个不用插件的办法。
第一、CSS样式部分


/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;}

第二、代码部分

function e_secret($atts, $content=null){
extract(shortcode_atts(array('key'=>null), $atts));<br> if(isset($_POST['e_secret_key']) && $_POST['e_secret_key']==$key){
return '
'.$content.'

';
}
else{
return '



';
}
}
add_shortcode('secret','e_secret');

添加到当前主题Functions.php文件中。
第三、如何使用

[secret key="设置密码"] 需要加密的内容部分

[/secret]

这样我们在添加内容的时候,直接用上面代码包含进来就可以实现部分内容加密。


扫描二维码,在手机上阅读!