小十的个人博客

@小十

born for design, do what you want, and carpe diem

文章 343
朋友 17
来访 1840

LATEST POSTS

RANKINGS

    • http://www.xiaoten.com
    • 网站成立5377天

    小十

    • 努力著

    仅关于ajax评论~

    ……从没写过跟技术沾边的文章……今天就借着小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……还好这个比较容易发现……改了之后只有细节有些不搭的问题,别的问题还好……

    看来模板函数写的不太一致……造成的这种不能正常运行的现象……等会儿再再虚拟机里测试一下默认主题……再比较一下函数……争取弄出来吧……

     

    Comments | NOTHING

      游客,你好 修改资料

    *邮箱和昵称必须填写