wordpress如何设置评论才能查看的内容

需要在你使用的主题里的functions.php 文件添加如下代码:

此文件在/www/wwwroot/www.cnbugs.com/wp-content/themes/ripro-v2,请根据你自己的主题文件进行检查位置

在functions.php文件底部添加如下代码

//部分内容评论可见
function reply_to_read($atts, $content = null) {
 extract(shortcode_atts(array("notice" => '<blockquote><center><p class="reply-to-read" style="color: blue;">注意:本段内容须成功“<a href="' . get_permalink() . '#respond" title="回复本文">回复本文</a>”后“<a href="javascript:window.location.reload();" title="刷新本页">刷新本页</a>”方可查看!</p></center></blockquote>') , $atts));
 $email = null;
 $user_ID = (int)wp_get_current_user()->ID;if ($user_ID > 0) {
 $email = get_userdata($user_ID)->user_email;//对博主直接显示内容
 $admin_email = get_bloginfo('admin_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');

使用方法:


[ reply]评论可见的内容[/reply]

[ reply notice="自定义的提示信息"]评论可见的内容[/reply]

看到的效果如下:

发表回复

后才能评论