将下面的代码复制到你使用的主题的functions.php最后,并把代码里面的“博主Email”改成你的,实现博主直接查看。
//wordpress隐藏内容回复后可见代码 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 = "service@77nn.net"; //把左面的邮箱换成博主Email if ($email == $admin_email) { return $content; } $email = get_userdata($user_ID)->user_email; //如果用户已登录,从登录信息中获取email }else if(isset($_COOKIE['comment_author_email_'.COOKIEHASH])){ $email=str_replace('%40','@',$_COOKIE['comment_author_email_'.COOKIEHASH]); //如果用户未登录但电脑上有本站的Cookie信息,从Cookie里读取email }else{ return $notice; //无法获取email,直接返回提示信息 } if(empty($email)){ return $notice; } global $wpdb; $post_id=get_the_ID(); //文章的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 $content; //查询到对应的已经审核通过的评论则返回内容 }else{ return $notice; //否则返回提示信息 } } add_shortcode('reply', 'reply_to_read');
添加了上面的代码就算完工了,发表文章时只需要添加
【reply]【/reply]
就可以使用了,下面是演示
此内容 评论 本文后刷新可见!
评论3