默认的公开程度是影响整篇文章的,从JKooll那里抄了个方法来加密段落。
首先在主题的functions.php里面加上一个function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
:::php
//Usage: [secret key="密码"]加密内容[/secret]
function e_secret($atts, $content=null) {
extract(shortcode_atts(array('key' => null, 'tip' => null), $atts));
if (
isset($_SESSION[hash('md5', $key)]) ||
(isset($_POST['e_secret_key']) && $_POST['e_secret_key'] == $key)
) {
$_SESSION[hash('md5', $key)] = $key;
return '<div class="e-secret">' . $content . '</div>';
} else {
if (isset($_POST['e_secret_key'])) {
$tip = '<p class="secret_tip">密码输入错误!</p>' . $tip;
}
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>' . '<p class="secret_tip">' . $tip . '</p>';
}
}
add_shortcode('secret', 'e_secret');
用法就是,如果在新式编辑器里,要添加一个html区块,然后这样把内容包起来:
1
[secret key="密码" tip="我是提示信息"]加密内容[/secret]
最后添加css样式优化一下外观:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
.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;
}
p.secret_tip {
clear: both;
}