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