kn007的个人博客
♥ You are here: Home > 软件与网络 > php > 分享两段代码,评论邮件样式和相关文章

分享两段代码,评论邮件样式和相关文章

by | 66 Comments

提醒:本文最后更新于 3937 天前,文中所描述的信息可能已发生改变,请仔细核实。

9954a147277615d094b802d041fb20

靠,好累啊,本想好好休息的。但是很多次的请求,我还是需要分享一下如题所说,大家都知道的代码。。。(只因某个一直被我笑的人连这些东东还要我分享)。少许郁闷,好困。。。看书看书,欢迎访问前一篇文章《周五了,马上周末了》。

值得一提的是,防机器人貌似效果显著,真正机器人都被挡到外面,欣慰一下。

另外还有一个要说的是,修复了缩略图大小错误。不好意思,有段代码写错了。


评论邮件提醒:(其实只是里面css漂亮)。一般放置在functions.php里的任意不引发语法错误的位置。请不要重复使用,免得收到过多的提醒邮件。

function comment_mail_notify($comment_id) {
   $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
 $comment = get_comment($comment_id);
 $parent_id = $comment->comment_parent ? $comment->comment_parent : '';
 $spam_confirmed = $comment->comment_approved;
 if (($parent_id != '') && ($spam_confirmed != 'spam')) {
   $wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
   $to = trim(get_comment($parent_id)->comment_author_email);
   $subject = '您在 [' . $blogname . '] 中的留言有了新的回复';
   $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:#666666; 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:#5692BC;font-weight:600;"
href="' . get_option('home') . '">' . $blogname . '
</a> 博客上的留言有回复啦!</span></div>
<div style="width:90%; margin:0 auto">
<p>您好, ' . trim(get_comment($parent_id)->comment_author) . '!</p>
<p>您发表在文章
《' . get_the_title($comment->comment_post_ID) . '》 的评论:
<p style="background-color: #EEE;border: 1px solid #DDD;
padding: 20px;margin: 15px 0;">' . nl2br(get_comment($parent_id)->comment_content) . '</p>
<p>' . trim($comment->comment_author) . ' 给您的回复如下:
<p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px;
margin: 15px 0;">' . nl2br($comment->comment_content) . '</p>
<p>您可以点击 <a style="text-decoration:none; color:#5692BC"
href="' . htmlspecialchars(get_comment_link($parent_id)) . '">查看回复的完整內容</a></p>
<p>欢迎再次光临 <a style="text-decoration:none; color:#5692BC"
href="' . get_option('home') . '">' . $blogname . '</a></p>
<p>(此邮件由系统自动发出, 请勿回复)</p>
</div>
</div>';
   $from = "From: \"" . $blogname . "\" <$wp_email>";
   $headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
   $message = convert_smilies($message);
   wp_mail( $to, $subject, $message, $headers );
 }
}
add_action('comment_post', 'comment_mail_notify');

相关文章函数:(图片需要post_thumbnail函数支持,一般(国产)主题会自带。)一般放置在sidebar.php里的合适位置,当然啦,还要有css支持,css我就懒得放了,因为这个是因主题而异。

<div class="Related_Posts"><ul><?php $post_num = 5;$exclude_id = $post->ID;$posttags = get_the_tags(); $i = 0;if ( $posttags ) {$tags = ''; foreach ( $posttags as $tag ) $tags .= $tag->term_id . ',';$args = array('post_status' => 'publish','tag__in' => explode(',', $tags),'post__not_in' => explode(',', $exclude_id),'ignore_sticky_posts' => 1,'orderby' => 'comment_date','posts_per_page' => $post_num);query_posts($args);while( have_posts() ) { the_post(); ?><li><a href="<?php the_permalink(); ?> " rel="nofollow"><?php post_thumbnail(); ?></a><div class="Related_Posts_tittle"><a class="Related_Posts_tittle" href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></div></li><?php $exclude_id .= ',' . $post->ID; $i ++;} wp_reset_query();}if ( $i < $post_num ) {$cats = ''; foreach ( get_the_category() as $cat ) $cats .= $cat->cat_ID . ',';$args = array('category__in' => explode(',', $cats),'post__not_in' => explode(',', $exclude_id),'ignore_sticky_posts' => 1,'orderby' => 'comment_date','posts_per_page' => $post_num - $i);query_posts($args);while( have_posts() ) { the_post(); ?><li><a href="<?php the_permalink(); ?> " rel="nofollow"><?php post_thumbnail(); ?></a><div class="Related_Posts_tittle"><a class="Related_Posts_tittle" href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></div></li><?php $i++;} wp_reset_query();}if ( $i  == 0 )  echo '<li>没有相关文章!</li>';?></ul></div>

转载请注明转自:kn007的个人博客的《分享两段代码,评论邮件样式和相关文章

donate
有所帮助?

Comments

66 Comments立即评论
  1. 你上次给我改的那邮件回复,怎么每次我收的都是两封! :oops:

    1. MOD回复

      @老猫Music: 因为你用了两次命令。。。你自己看一下。。。是不是重了

  2. 回复

    我发现这个貌似不是 。。。

    1. MOD回复

      @babytomas: 呵呵,新版的没共享出来,因为是改别人的 :arrow:

    2. 回复

      @kn007: :cry: 求共享

    3. MOD回复

      @babytomas: 额,这个你可以在帖子 https://kn007.net/topics/wretched-new-comments-e-mail-alert-style/ 中里面的ben找他要一份。请支持原创

    4. 回复

      @kn007: :mrgreen: 好的好的~

    5. MOD回复

      @babytomas: 谢谢支持 :grin:

  3. 回复

    :mrgreen: 我也弄了个美化版!自己觉得还行吧

    1. MOD回复

      @chonghua: 自己感觉可以就好了

icon_wink.gificon_neutral.gificon_mad.gificon_twisted.gificon_smile.gificon_eek.gificon_sad.gificon_rolleyes.gificon_razz.gificon_redface.gificon_surprised.gificon_mrgreen.gificon_lol.gificon_idea.gificon_biggrin.gificon_evil.gificon_cry.gificon_cool.gificon_arrow.gificon_confused.gificon_question.gificon_exclaim.gif