……从没写过跟技术沾边的文章……今天就借着小T和Willin的经验写个关于Ajax评论的文章,也就把自己测试的经历描述一下……没有一点属于自己的东西在里面,写着都怪不好意思的…… 嗯,正文开始…… 首先,我是本着评论回应邮件提醒的目的来弄这个ajax评论的……可能是这个主题的函数跟willin所给出的《Comment Mail Notify》函数不同……只要一添加那一堆东西如下: /* comment_mail_notify v1.0 by willin kan. (有勾選欄, 由訪客決定) */ function comment_mail_notify($comment_id) { $admin_notify = '1'; // admin 要不要收回覆通知 ( '1'=要 ; '0'=不要 ) $admin_email = get_bloginfo ('admin_email'); // $admin_email 可改為你指定的 e-mail. $comment = get_comment($comment_id); $comment_author_email = trim($comment->comment_author_email); $parent_id = $comment->comment_parent ? $comment->comment_parent : ''; global $wpdb; if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '') $wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;"); if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1')) $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'"); $notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0'; $spam_confirmed = $comment->comment_approved; if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') { $wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 發出點, no-reply 可改為可用的 e-mail. $to = trim(get_comment($parent_id)->comment_author_email); $subject = '您在 [' . get_option("blogname") . '] 的留言有了回應'; $message = ' ' . trim(get_comment($parent_id)->comment_author) . ', 您好! 您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言: ' . nl2br(get_comment($parent_id)->comment_content) . ' ' . trim($comment->comment_author) . ' 給您的回應: ' . nl2br($comment->comment_content) . ' 您可以點擊 查看回應完整內容 歡迎再度光臨 ' . get_option('blogname') . ' (此郵件由系統自動發出, 請勿回覆.) '; $from = "From: "" . get_option('blogname') . "" <$wp_email>"; $headers = "$fromnContent-Type: text/html; charset=" . get_option('blog_charset') . "n"; wp_mail( $to, $subject, $message, $headers ); //echo 'mail to ', $to, ' ' , $subject, $message; // for testing } } add_action('comment_post', 'comment_mail_notify'); /* 自動加勾選欄 */ function add_checkbox() { echo '有人回覆時郵件通知我'; } add_action('comment_form', 'add_checkbox'); // -- END ---------------------------------------- 整个博客就不能正常运行了……所以,这个就先搁置那了,然后根据小T博客中ajax评论的效果,尝试了一下《WordPress 內置嵌套評論專用 Ajax comments》提到的方法,没想到还挺顺利,唯独按照他其中提到的上传两个文件后,然后修改header.php的过程中所要取代内容中所含的template_directory在我的模版中改为template_url……还好这个比较容易发现……改了之后只有细节有些不搭的问题,别的问题还好…… 看来模板函数写的不太一致……造成的这种不能正常运行的现象……等会儿再再虚拟机里测试一下默认主题……再比较一下函数……争取弄出来吧…… Loading... ……从没写过跟技术沾边的文章……今天就借着小T和Willin的经验写个关于Ajax评论的文章,也就把自己测试的经历描述一下……没有一点属于自己的东西在里面,写着都怪不好意思的…… 嗯,正文开始…… <!--more--> 首先,我是本着评论回应邮件提醒的目的来弄这个ajax评论的……可能是这个主题的函数跟willin所给出的《<span class="Apple-style-span" style="font-size: 12px; line-height: 17px;"><a title="Comment Mail Notify" href="http://kan.willin.org/?p=1295" target="_blank" rel="bookmark">Comment Mail Notify</a></span>》函数不同……只要一添加那一堆东西如下: <pre lang="php" line="1">/* comment_mail_notify v1.0 by willin kan. (有勾選欄, 由訪客決定) */ function comment_mail_notify($comment_id) { $admin_notify = '1'; // admin 要不要收回覆通知 ( '1'=要 ; '0'=不要 ) $admin_email = get_bloginfo ('admin_email'); // $admin_email 可改為你指定的 e-mail. $comment = get_comment($comment_id); $comment_author_email = trim($comment->comment_author_email); $parent_id = $comment->comment_parent ? $comment->comment_parent : ''; global $wpdb; if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '') $wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;"); if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1')) $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'"); $notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0'; $spam_confirmed = $comment->comment_approved; if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') { $wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 發出點, no-reply 可改為可用的 e-mail. $to = trim(get_comment($parent_id)->comment_author_email); $subject = '您在 [' . get_option("blogname") . '] 的留言有了回應'; $message = ' <div style="background-color: #eef2fa; border: 1px solid #d8e3e8; color: #111; padding: 0 15px; -moz-border-radius: 5px; -webkit-border-radius: 5px; -khtml-border-radius: 5px; border-radius: 5px;"> ' . trim(get_comment($parent_id)->comment_author) . ', 您好! 您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言: ' . nl2br(get_comment($parent_id)->comment_content) . ' ' . trim($comment->comment_author) . ' 給您的回應: ' . nl2br($comment->comment_content) . ' 您可以點擊 <a href="' . htmlspecialchars(get_comment_link($parent_id)) . '">查看回應完整內容</a> 歡迎再度光臨 <a href="' . get_option('home') . '">' . get_option('blogname') . '</a> (此郵件由系統自動發出, 請勿回覆.) </div> '; $from = "From: "" . get_option('blogname') . "" <$wp_email>"; $headers = "$fromnContent-Type: text/html; charset=" . get_option('blog_charset') . "n"; wp_mail( $to, $subject, $message, $headers ); //echo 'mail to ', $to, ' ' , $subject, $message; // for testing } } add_action('comment_post', 'comment_mail_notify'); /* 自動加勾選欄 */ function add_checkbox() { echo '<input id="comment_mail_notify" style="margin-left: 20px;" checked="checked" name="comment_mail_notify" type="checkbox" value="comment_mail_notify" /><label for="comment_mail_notify">有人回覆時郵件通知我</label>'; } add_action('comment_form', 'add_checkbox'); // -- END ---------------------------------------- </pre> 整个博客就不能正常运行了……所以,这个就先搁置那了,然后根据小T博客中ajax评论的效果,尝试了一下《<a title="WordPress 內置嵌套評論專用 Ajax comments" href="http://kan.willin.org/?p=1271" target="_blank" rel="bookmark">WordPress 內置嵌套評論專用 Ajax comments</a>》提到的方法,没想到还挺顺利,唯独按照他其中提到的上传两个文件后,然后修改header.php的过程中所要取代内容中所含的template_directory在我的模版中改为template_url……还好这个比较容易发现……改了之后只有细节有些不搭的问题,别的问题还好…… 看来模板函数写的不太一致……造成的这种不能正常运行的现象……等会儿再再虚拟机里测试一下默认主题……再比较一下函数……争取弄出来吧…… © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏