說到這個 WordPress 回覆可見的功能,小編早在多年前就嘗試過,但是會有一些問題,比如使用多說導致回覆後,不能立刻顯示內容,所以就取消了這個功能,但是如果是用 WordPress 自帶評論模組的話,那麼這個功能,可謂是秒回秒可見哈!
下面我們直接說教程吧
這塊,我就不推薦大家用什麼外掛了。完全加入程式碼即可 OK!
在 WordPress 主題檔案的 functions.php 內加入以下程式碼:
- function reply_to_read($atts, $content=null) {
- "notice" => '<p class="reply-to-read"> 溫馨提示: 此處內容需要<a href="#respond" title="評論本文"> 評論本文</a> 後才能檢視.</p>'), $atts));
- $email = null;
- int) wp_get_current_user()->ID;
- if ($user_ID > 0) {
- "[email protected]";
- 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;
- }
- $post_id = get_the_ID();
- "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;
- }
將程式碼裡的郵箱替換成我們自己的,新增好後,儲存即可!
之後我們在編寫文章的時候就可以新增短程式碼來實現 WordPress 回覆可見的功能了!
或者
- [@reply notice="自定義的提示資訊"] 評論可見的內容 [@/reply]
大家注意下,小編為了讓程式碼展現出來,在程式碼里加了 @,大家在使用的時候把 @去掉!functions.php 內的程式碼僅替換郵箱即可!!!