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

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

by | 66 Comments

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

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
有所帮助?
Tags: ,
Comments
66 Comments立即评论
  1. LV4
    回复

    七七伟大啦,还没人评论。我来占个沙发吧···· :roll: :roll: :roll: :roll:

    1. MOD
      回复

      @天域剑客: 好吧。笑你一下。。 :lol:

  2. LV3
    回复

    要是以前我肯定拿去折腾,不过最近累趴了,收藏个吧,以后有时间再弄弄看

    1. MOD
      回复

      @CrazyM: 好吧。。年底一般都忙啊

  3. LV6
    回复

    又是地板 :x :x

    1. MOD
      回复

      @Xider: 可怜的娃

    2. LV6
      回复

      @kn007: :o 我离板凳只有一分钟有木有

    3. MOD
      回复

      @Xider: 哈哈哈,你慢了~ :mrgreen: ,我看到的10几秒~~

    4. LV6
      回复

      @kn007: 不带这样的吧...深坑啊 :o :o

    5. MOD
      回复

      @Xider: 更新了你友情链接

    6. LV6
      回复

      @kn007: OK我明白了

    7. MOD
      回复

      @Xider: 其实你这算好了。。。以前一博友的博客,3楼是拖出去斩了。。我每次都是3楼 :cry: 那才叫坑爹呢

    8. LV6
      回复

      @kn007: :o 看来你的命运比我悲催...我觉得我也应该折腾个前三楼的特别称呼 :cool:

    9. MOD
      回复

      @Xider: 好吧。。。不要搞得太坑爹了

  4. LV6
    回复

    快发mail来~

    1. MOD
      回复

      @凤翼天堂: :o 你收的还不够多啊

    2. LV6
      回复

      @kn007: :o 说好的 新的呢

    3. MOD
      回复

      @凤翼天堂: 什么新的呢? :?:

    4. LV6
      回复

      @kn007: 新评论邮件样式QAQ还以为是更漂亮的类型

    5. MOD
      回复

      @凤翼天堂: :o 没想改变,目前

  5. LV6
    回复

    :cool: 相关文章我倒是不想多加功能了=w=

    1. MOD
      回复

      @凤翼天堂: 你那不需要这个功能吧。。。

    2. LV6
      回复

      @kn007: 没错没错=0=不过说好的新样式呢

    3. MOD
      回复

      @凤翼天堂: 我有说要发新样式吗?不过这个以后可能都不会怎么考虑。。。。就这样不是挺好的

    4. LV6
      回复

      @kn007: 标题和第一段QAQ 因为大家都用一样的想换胃口

    5. MOD
      回复

      @凤翼天堂: 新评论。。。好吧理解有误差。。。我改下标题神马的

    6. LV6
      回复

      @kn007: :o 哈怎么断句= =|||

    7. MOD
      回复

      @凤翼天堂: 新评论,就是有人发新的评论。。。而不是新的版面的意思 :???:

    8. LV6
      回复

      @kn007: 好吧我是连着后面样式什么的一起读的……

    9. MOD
      回复

      @凤翼天堂: 好吧,世界如此坑爹。。下次一定要多读几次才能发。不然坑爹了。。 :???:

    10. MOD
      回复

      @凤翼天堂: 同感,我这个分享了4、5个人了。。。郁闷了

    11. MOD
      回复

      @凤翼天堂: 被你这么一说,,,貌似是得改改

    12. LV6
      回复

      @kn007: :mrgreen: 求新代码偷偷分享给哥就好了 :mrgreen:

    13. MOD
      回复

      @凤翼天堂: 好说,好说,等哥来灵感了,啥都没问题 :cool:

    14. LV6
      回复

      @kn007: :mrgreen: 最近ben-lab那个就不错

    15. MOD
      回复

      @凤翼天堂: 或许你可以将他的邮件转发给我。。 :lol:

    16. MOD
      回复

      @凤翼天堂: 试下新的回复邮件样式

    17. LV6
      回复

      @kn007: 我也玩

    18. MOD
      回复

      @凤翼天堂: 再试试效果

    19. LV6
      回复
    20. MOD
      回复

      @凤翼天堂: 去除mailbg效果尝试

    21. LV6
      回复
  6. LV2
    回复

    你知道嘛?在rss中看这文章,还以为一堆乱码

    1. MOD
      回复

      @Musk: ...........不是吧。。。看了下,确实挺像乱码的。。。这没办法。。这源码本来就没整理

    2. MOD
      回复

      @Musk: 用IE看就不会了。。。

    3. MOD
      回复

      @Musk: chrome对rss,直接xml看。。。真心坑爹的乱

  7. LV2
    回复

    我就想让你回复下我看看效果 :lol:

    1. MOD
      回复

      @花生米: 可以,不过我准备换一下。。

  8. LV5
    回复

    只因某个一直被我笑的人连这些东东还要我分享。谁啊? :mrgreen:

    1. MOD
      回复

      @Hannah: 看下1楼,你就明白了

  9. LV2
    回复

    那个邮件回复样式的代码看着很好啊,谢谢分享

    1. MOD
      回复

      @蚊哥's Blog: 现在又用心的了 :oops:

  10. LV3
    回复

    这代码不是人看的 :lol:

    1. MOD
      回复

      @L-JH: :o 为毛这样说/。//

    2. LV3
      回复

      @kn007: 杂乱无章 :mrgreen:

    3. MOD
      回复

      @L-JH: 我佛慈悲,故意让你们难看 :evil:

;-):|:x:twisted::smile::shock::sad::roll::razz::oops::o:mrgreen::lol::idea::grin::evil::cry::cool::arrow::???::?::!: