评论可见一般经常会在论坛上看到,尤其是一些下载论坛,有时候遇见多了觉得挺讨厌的,不过想一想谁让你是伸手党呢?下载人家的东西连个回复都没有。于是轮到我们提供下载资源时我们也可以这样做,在wordpress当然也能实现,或许会增加些访客评论的积极性或许也会增加不少垃圾评论。

方法如下:

[reply]

首先推荐一款实现该功能的插件:easy2hide

使用方法,启用插件后,在编辑文章时加入:



  1. <!--easy2hide start{reply_to_this=true}-->一些隐藏内容<!--easy2hide end-->    



 

下面再说说不用插件的实现方法:

把下面代码加到主题functions.php文件中



  1. function reply_to_read($atts, $content=null) {      

  2.         extract(shortcode_atts(array("notice" => '<p class="reply-to-read">温馨提示: 此处内容需要<a href="#respond" title="评论本文">评论本文</a>后才能查看.</p>'), $atts));      

  3.         $email = null;      

  4.         $user_ID = (int) wp_get_current_user()->ID;      

  5.         if ($user_ID > 0) {      

  6.             $email = get_userdata($user_ID)->user_email;      

  7.             //对博主直接显示内容      

  8.             $admin_email = "xxx@aaa.com"; //博主Email      

  9.             if ($email == $admin_email) {      

  10.                 return $content;      

  11.             }      

  12.         } else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {      

  13.             $email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);      

  14.         } else {      

  15.             return $notice;      

  16.         }      

  17.         if (emptyempty($email)) {      

  18.             return $notice;      

  19.         }      

  20.         global $wpdb;      

  21.         $post_id = get_the_ID();      

  22.         $query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";      

  23.         if ($wpdb->get_results($query)) {      

  24.             return do_shortcode($content);      

  25.         } else {      

  26.             return $notice;      

  27.         }      

  28.     }      

  29.        

  30.     add_shortcode('reply', 'reply_to_read');    



自行修改其中的博主Email地址。

使用方法,编辑文章时添加:



  1. 【reply】评论可见的内容【/reply】    



或者



  1. 【reply notice="自定义的提示信息"】 评论可见的内容【/reply】    



(使用时把上面的“【 】”号改为“[ ]”号)

使用后只有一个问题那就是只有评论通过审核后才能看到内容,在审核状态下还是不能看到内容,建议想使用这个功能的童鞋可以关闭Wordpress评论审核功能。

[/reply]


最后修改:2019 年 06 月 06 日
收藏不易,如果感觉对你有用,请随意打赏支持下