説到這個 WordPress 回覆可見的功能,小編早在多年前就嘗試過,但是會有一些問題,比如使用多説導致回覆後,不能立刻顯示內容,所以就取消了這個功能,但是如果是用 WordPress 自帶評論模塊的話,那麼這個功能,可謂是秒回秒可見哈!

下面我們直接説教程吧

這塊,我就不推薦大家用什麼插件了。完全加入代碼即可 OK!

WordPress 主題文件的 functions.php 內加入以下代碼:

  1. function reply_to_read($atts, $content=null) {     
  2. "notice" => '<p class="reply-to-read"> 温馨提示: 此處內容需要<a href="#respond" title="評論本文"> 評論本文</a> 後才能查看.</p>'), $atts));     
  3.         $email = null;     
  4. int) wp_get_current_user()->ID;     
  5.         if ($user_ID > 0) {     
  6.               
  7. "[email protected]"  
  8.             if ($email == $admin_email) {     
  9. return $content;     
  10.             }     
  11. else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {     
  12.             $email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);     
  13. else {     
  14.             return $notice;     
  15.         if (empty($email)) {     
  16. return $notice;     
  17.         }     
  18.         $post_id = get_the_ID();     
  19. "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";     
  20.         if ($wpdb->get_results($query)) {     
  21. return do_shortcode($content);     
  22.         } else {     
  23. return $notice;     
  24.         }     
  25.       

將代碼裏的郵箱替換成我們自己的,添加好後,保存即可!

之後我們在編寫文章的時候就可以添加短代碼來實現 WordPress 回覆可見的功能了!

或者

  1. [@reply notice="自定義的提示信息"] 評論可見的內容 [@/reply]    

大家注意下,小編為了讓代碼展現出來,在代碼里加了 @,大家在使用的時候把 @去掉!functions.php 內的代碼僅替換郵箱即可!!!