說到這個 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 內的程式碼僅替換郵箱即可!!!