On many sites have seen this effect, such as the site of the enemy, his part of the resources are needed for our comments to download, then what is the use of this, for me, in addition to the loading force, but also to increase the number of my comments, not many said, first look at the effect:
In fact, WordPress has a lot of plug-ins can realize this function, such as easy2hide, but the plug is of course less the better, below I say how to implement this function with code:
the original text on the Internet:Add the following code to the functions.php file in the current topic:
1234567891011121314151617181920212223242526272829 |
function reply_to_read(
$atts
,
$content
=null) {
extract(shortcode_atts(
array
(
"notice" =>
‘<p class="reply-to-read" style="border-width: 1px 1px 1px 1px;border-color: #F2F2F2;line-height: 150%;"><blockquote><font color="#ff0000"><b>温馨提示</b></font>: 隐藏内容需要<a href="#respond" title="点击进行评论"> 回复评论 </a>后才能查看, 评论后请 <strong><a href="javascript:location.reload()" title="点击刷新"> 刷新 !</a></strong>.</blockquote></p>‘
),
$atts
));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if (
$user_ID > 0) {
$email = get_userdata(
$user_ID
)->user_email;
//对博主直接显示内容
$admin_email =
"[email protected]"
;
//把左面的邮箱换成博主Email
if (
$email ==
$admin_email
) {
return $content
;
}
}
else if (isset(
$_COOKIE
[
‘comment_author_email_‘ . COOKIEHASH])) {
$email =
str_replace
(
‘%40‘
,
‘@‘
,
$_COOKIE
[
‘comment_author_email_‘ . COOKIEHASH]);
}
else {
return $notice
;
}
if (
empty
(
$email
)) {
return $notice
;
}
global $wpdb
;
$post_id = get_the_ID();
$query =
"SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`=‘1‘ and `comment_author_email`=‘{$email}‘ LIMIT 1"
;
if (
$wpdb
->get_results(
$query
)) {
return do_shortcode(
$content
);
}
else {
return $notice
;
}
}
add_shortcode(
‘reply‘
,
‘reply_to_read‘
);
|
Note: replace the "[email protected]" in the code with the blogger email address
I modified the code:I started to use the code directly on the Internet, but found that the effect was wrong, so I changed the label and style, and then modified their own mailbox number. Other parts of the code do not need to be modified.
1234567891011121314151617181920212223242526272829 |
function reply_to_read(
$atts
,
$content
=null) {
extract(shortcode_atts(
array
(
"notice" =>
‘<p class="reply-to-read" style="text-align:center; border:2px solid #f00; border-style:dotted; border-radius:4px; padding:5px; margin:10px;"><strong style="color: red;">温馨提示:</strong>为了避免资源链接被和谐,此处内容需要您<strong><a href="#respond" title="点击进行评论"> 回复评论 </a></strong>后才能查看, 评论后请 <strong><a href="javascript:location.reload()" title="点击刷新"> 刷新!</a></strong></p>‘
),
$atts
));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if (
$user_ID > 0) {
$email = get_userdata(
$user_ID
)->user_email;
//对博主直接显示内容
$admin_email =
"[email protected]"
;
//把左面的邮箱换成博主Email
if (
$email ==
$admin_email
) {
return $content
;
}
}
else if (isset(
$_COOKIE
[
‘comment_author_email_‘ . COOKIEHASH])) {
$email =
str_replace
(
‘%40‘
,
‘@‘
,
$_COOKIE
[
‘comment_author_email_‘ . COOKIEHASH]);
}
else {
return $notice
;
}
if (
empty
(
$email
)) {
return $notice
;
}
global $wpdb
;
$post_id = get_the_ID();
$query =
"SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`=‘1‘ and `comment_author_email`=‘{$email}‘ LIMIT 1"
;
if (
$wpdb
->get_results(
$query
)) {
return do_shortcode(
$content
);
}
else {
return $notice
;
}
}
add_shortcode(
‘reply‘
,
‘reply_to_read‘
);
|
This can let others only reply to the comments to download your site resources, is not very strong, I just used this today to have a new comment on it.
Reference URL: http://www.boke8.net/the-wp-post-visible-when-comments.html
Pure Code Implementation wordpress article hidden content comments visible