代码实现WordPress评论回复样式

之前就在网上看过怎么用代码实现wordpress评论回复,也有很多“比较懒”的用户直接用插件实现的。

我一直都在用ConcisePro主题,发现它其实自带了代码实现评论回复功能的,就一直没有理会,但是有次看到好几个博主给我的回评通知都非常好看,于是就也想改改。先放出图看看,喜欢的就在看如何实现的把!

20130801082941

把下面代码添加到你的主题的函数模板 functions.php文件即可,我的主题是加到 \includes\functions.php。

  1. // 评论回应邮件通知   
  2. function comment_mail_notify($comment_id) {   
  3.   $admin_notify = ‘1’; // admin 要不要收回覆通知 ( ‘1’=要 ; ‘0’=不要 )   
  4.   $admin_email = ‘no-reply@itzxs.com’; // $admin_email 可改为你指定的 e-mail.   
  5.   $comment = get_comment($comment_id);   
  6.   $comment_author_email = trim($comment->comment_author_email);   
  7.   $parent_id = $comment->comment_parent ? $comment->comment_parent : ;   
  8.   global $wpdb;   
  9.   if ($wpdb->query(“Describe {$wpdb->comments} comment_mail_notify”) == )   
  10.     $wpdb->query(“ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;”);   
  11.   if (($comment_author_email != $admin_email && isset($_POST[‘comment_mail_notify’])) || ($comment_author_email == $admin_email && $admin_notify == ‘1’))   
  12.     $wpdb->query(“UPDATE {$wpdb->comments} SET comment_mail_notify=’1′ WHERE comment_ID=’$comment_id'”);   
  13.   $notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : ‘0’;   
  14.   $spam_confirmed = $comment->comment_approved;   
  15.   if ($parent_id !=  && $spam_confirmed != ‘spam’ && $notify == ‘1’) {   
  16.     $wp_email = ‘no-reply@’ . preg_replace(‘#^www\.#’, strtolower($_SERVER[‘SERVER_NAME’])); // e-mail 发出点, no-reply 可改为可用的 e-mail.   
  17.     $to = trim(get_comment($parent_id)->comment_author_email);   
  18.     $subject = ‘ 您在 [‘ . get_option(“blogname”) . ‘] 的留言有了新回应’;   
  19.          $message = ‘<div style=“background-color:#FFF; border:1px solid #666666; color:#111; -moz-border-radius:8px; -webkit-border-radius:8px; -khtml-border-radius:8px; border-radius:8px; font-size:12px; width:702px; margin:0 auto; margin-top:10px; font-family:微软雅黑, Arial;”>   <div style=“background:#2c9b0a; width:100%; height:60px; color:white; -moz-border-radius:6px 6px 0 0; -webkit-border-radius:6px 6px 0 0; -khtml-border-radius:6px 6px 0 0; border-radius:6px 6px 0 0; “><span style=“height:60px; line-height:60px; margin-left:30px; font-size:12px;”>您在 <a style=“text-decoration:none; color:#000;font-weight:600;” href=“‘ . get_option(‘home’) . ‘”><strong>’ . get_option(“blogname”) . ‘</strong></a> 上<strong>《’ . get_the_title($comment->comment_post_ID) . ‘》</strong>有一个评论回复</span></div>   
  20. <div style=“width:90%; margin:0 auto”><br/><p>您在<strong>《’ . get_the_title($comment->comment_post_ID) . ‘》</strong>留下的评论是:</p>   
  21. <p style=“background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;”>’ . nl2br(get_comment($parent_id)->comment_content) . ‘</p>   
  22. <p>’ . trim($comment->comment_author) . ‘ 给您的新回复如下:<p style=“background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;”>’ . nl2br($comment->comment_content) . ‘</p>   
  23. <p>您可以点击“<a href=“‘ . htmlspecialchars(get_comment_link($parent_id)) . ‘”>这里</a>”查看评论   
  24. </p>如果你不能点击上面的链接可以吧下面的链接复制到地址栏中访问   
  25. <p style=“background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;”><a href=“‘ . htmlspecialchars(get_comment_link($parent_id)) . ‘”>’ . htmlspecialchars(get_comment_link($parent_id)) . ‘</a></p>   
  26. <p>欢迎再次光临 <a style=“text-decoration:none; color:#2c9b0a” href=“‘ . get_option(‘home’) . ‘”>’ . get_option(‘blogname’) . ‘</a></p>   
  27. <p>注意:此邮件由系统发出,请勿回复!</p>   
  28. </div></div>’;   
  29.     $from = “From: \”” . get_option(‘blogname’) . “\” <$wp_email>”;   
  30.     $headers = “$from\nContent-Type: text/html; charset=” . get_option(‘blog_charset’) . “\n”;   
  31.     wp_mail( $to$subject$message$headers );   
  32.     //echo ‘mail to ‘, $to, ‘<br/> ‘ , $subject, $message; // for testing   
  33.   }   
  34.     }    
  35. add_action(‘comment_post’, ‘comment_mail_notify’);   
  36.   
  37.   
  38. // 自动勾选    
  39. function add_checkbox() {   
  40.   echo ‘<input type=“checkbox” name=“comment_mail_notify” id=“comment_mail_notify” value=“comment_mail_notify” checked=“checked” style=“margin-left:0px;” /><label for=“comment_mail_notify”>有人回复时邮件通知我</label>’;   
  41. };  

原创文章,作者:wwh,如若转载,请注明出处:https://www.wuwenhui.cn/2764.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
wwhwwh
上一篇 2013-08-01
下一篇 2013-08-06

相关推荐

  • wordpress添加返回顶部按钮

    一直都想给WordPress添加一个返回顶部的按钮,我知道可以有这类型的插件,但不想用插件。于是网上查看了一些文章,找到了一个从百度搜索风云榜这里扒出来的JS代码。 1、找到“返回…

    2012-11-16
    50.2K15
  • Google服务被“封”WordPress后台慢

    前段时间,Google服务国内都被封掉了,wordpress默认有个Google字体加载的链接,因为被封的原因,导致网站后台打开速度很慢,这里找了个解决方法。 打开WordPres…

    2014-08-21
    5.4K1

回复 1111

登录后才能评论

评论列表(7条)

  • 陌小雨
    陌小雨 2014-11-04 09:37

    很不错哦,博主! :razz:

  • 1111
    1111 2014-12-24 17:48

    很不错,学习了

  • 阿夫瑞
    阿夫瑞 2015-12-30 21:22

    不错

  • 我爱动感单车网
    我爱动感单车网 2016-10-23 00:14

    :arrow: 为这个功能已经弄过不知多少次了,但是一直弄不成功啊,好纠结郁闷!

  • 我爱动感单车网
    我爱动感单车网 2016-10-27 13:50

    真心不错,这个样式相当的美观!

  • 12345
    12345 2017-05-23 11:16

    为什么放到functions.php里面,前台用 调用,显示functions.php里面的第一段代码function comment_mail_notify($comment_id) { 错误

联系我们

在线咨询:点击这里给我发消息

站长邮箱:admin@wuwenhui.cn
工作时间:周一至周五,8:30-17:30,节假日休息

微信
本站支持QQ一键注册登录,所有资源下载均在文章底部~