
前段时间万戈说我骗PV。
杯具,这真的是杯具。我想熟悉我的朋友都知道,我是个完完全全的代码盲,所用的效果什么,全部都是跟着万戈一步一步画瓢画出来的。去别的博客溜达,大部分都会有回复的邮件通知,这样很方便。可是我这里没有,不是我不想加,而是真的不知道。后来在万戈和willin大师的双重帮助下,终于成功完成了。
小博的两个变化,评论的再编辑,和回复邮件通知。特记录方法如下:
首先,下载两个程序中的随便一个。(我用的第一个)上传到主题文件夹下
程式下載: 下載 comments-ajax.zip (8.90k)(v1.26 2009/10/21 更新)
下載 comments-ajax(no-edit).zip (7.96k)(v1.26 2009/10/21 更新, "無再編輯版" )
打开header.php,在其中找到
<!--p if ( is_singular() ) wp_enqueue_script( 'comment-reply' );-->
改为
<!--p if ( is_singular() ) wp_enqueue_script( 'comment-reply' );--> 改为 <!--p if ( is_singular() ){--> <script src="/wp-content/themes/D-Z-Theme-Pro_CP_Green/comments-ajax.js" type="text/javascript"><!--mce:0--></script> <!--p }-->
这样来说,如果你的模板夠标准,这樣就可以正常工作了,但是我的博客偏偏不行,评论时会出现大堆的代码,所以在comments.php里面还需要更改。
<div id="comments" class="comments-template"> <!--p if ( have_comments() ) :--> <!--p if ( ! empty($comments_by_type['comment']) ) :--> <h2>本文评论 <!--p comments_number('No comment', '<span class="comments-num">1</span> comment', '<span class="comments-num">%</span> comments' )--></h2> </div>
这是原主题里的代码,要修改成:
<div class="comments-template"> <!--p if ( have_comments() ) :--> <!--p if ( ! empty($comments_by_type['comment']) ) :--> <h2 id="comments">本文评论 <!--p comments_number('No comment', '1 comment', '% comments' )--></h2> </div>
这样一来,我的博客才算是成功加上这个功能了。接下来willin大师登场。因为这个模板的侧边栏含有JQ,所以侧边栏在回复以后出现了变形。解决未果,求教willin,并把模板发送给willin帮忙修改,大师也相当热心的,很快就给了我回复,并把成功修改后的模板给了我,OK,继续最后一个,加上邮件回复的代码!
將下段 copy 到 comments-ajax.php 的最下面, 注意是 php 代碼, 要居於 之中.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <?php //增加:評論回應郵件通知功能 $parent_id = $comment->comment_parent; $to = trim( get_comment( $parent_id )->comment_author); $admin = '张三';//改為你的名字. if (($comment_parent != 0 ) && ($to != $admin) && ($comment_author == $admin)) { /* 上面的判斷式,決定發出郵件的必要條件: ($comment_parent != 0 ) :回覆的才可發. ($to != $admin) :不發給 admin. ($comment_author == $admin) :admin 的回覆才可發. 可視個人需求修改以上條件. */ $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;"> <p>' . trim( get_comment( $parent_id )->comment_author) . ', 您好!</p> <p>您曾在《' . get_the_title( $comment->comment_post_ID ) . '》的留言:<br /> ' . trim( get_comment( $parent_id )->comment_content) . '</p> <p>' . $comment_author . ' 給您的回應:<br /> ' . $comment_content . '<br /></p> <p>您可以點擊 <a href="' . get_comment_link($parent_id) . '">查看回應完整內容</a></p> <p>歡迎再度光臨 <a href="' . get_option('home') . '">' . get_option('blogname') . '</a></p> <p>(此郵件由系統自動發出, 請勿回覆.)</p> </div> '; $from = "From: \"" . get_option('blogname') . "\" <$wp_email>"; $headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n"; wp_mail( $to, $subject, $message, $headers ); } ?> |
$subject 是邮件的标题, $message 是邮件的内容, 你可试着变化一下.这个又是全世界最短的 "评论回应邮件通知" 了!
有些人问到是否可以加个选项, 可让留言者自己选择是否要邮件通知.我的看法是越简单越好, 程式加多了反而是累赘, 还不如用插件.
其实也很简单,下面把willin的方法贴出来。
1. 先在 comments.php 的 id="submit" 的上一行插入:
<input id="comment_mail_notify" style="width: auto;" checked="checked" name="comment_mail_notify" type="checkbox" value="comment_mail_notify" /><label for="comment_mail_notify">有人回复时邮件通知我</label>
2. 再把上面 comments-ajax.php 代码的:
if (($comment_parent != 0 ) && ($to != $admin) && ($comment_author == $admin)) {
那一行替换成:
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 (isset($_POST['comment_mail_notify'])){ $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'"); } $notify = get_comment($parent_id)->comment_mail_notify; if (($comment_parent != 0 ) && ($to != $admin) && ($comment_author == $admin) && ($notify == 1 )) {
-The End-
» 本文链接地址:http://zhang3.net/archives/1176» 订阅本站:http://feed.zhang3.net

每次在键盘前生硬的组合这些文字时,我总想用最简单自白的语言来构造,希望能超越自己的从前,不知不觉得就陷入了一个怪圈,开始不知所措的喃喃自语。
本文评论 84 comments
学习一下先,不过你的评论框里面的图片很搞哎。
翻体字….一看就头晕…
我也来测试一下效果看看
看在我也是Willin的份上,到我的博客帮我测试一下 OK?
我刚装上邮件回复。
哈哈,没问题……
晕。。问题颇多,加我QQ,234874,明天跟你共同探讨。
这话说的好伤心吖。。。虽然PHP不怎么懂,Ajax或jQuery更不懂
我晕。。我没别的意思,我也不懂的。。只是去你那里,连句话也没留上。