如何不使用插件即可支持Gravatar

Posted in WordPress / 软硬一本 @ Oct 24th, 2007 by underone |

在做了新的皮肤之后,我一直在考虑是不是要打开Gravatar,因为有一阵Gravatar确实慢的可怕。

在得知Automattic收购Gravatar之后,WordPress对头像的默认支持那便是很自然的事情……也就是说,从此各种Gravatar插件也许和TAG插件一样将逐渐消失……处于私心,我对这事很抗拒,具体就不说了……

Matt说只写了两行代码支持Gravatar,我没找到代码是怎样的,但是经过实验,以下的代码是绝对可行的(记得关掉现在的插件)。

  1. < ?php 
  2. if ( !empty( $comment->comment_author_email ) ) {
  3. $md5 = md5( $comment->comment_author_email );
  4. $default = urlencode( 'http://www.yourwebsite.com/image/you.png' );
  5. echo "<img style='float: right; margin-left: 10px;' src='http://www.gravatar.com/avatar.php?gravatar_id=$md5&amp;size=60&amp;default=$default' alt='' />";
  6. }
  7. ?>

这些代码需要插到你的comments.php中去。

当然,我们也不能忘了使用插件的办法:

1、下载插件:http://site.gravatar.com/plugins/wp_gravatar.zip
2、激活插件
3、在适当的地方插入代码,以我之前用的为例子,大概是这样的(详细说明看这里):

  1. < ?php if (function_exists("gravatar")) { ?><img src="<?php gravatar("R", 30, "http://www.underone.com/files/g_old.jpg"); ?/>" alt="Gravatar" class="gravatar" width="32" height="32" />< ?php } ?>

本文精巧网址: http://go.6.cn/c08p

延展阅读

22 Responses to “如何不使用插件即可支持Gravatar”

  1. underone  Reply to this comment

    留言就是个现成的例子。。。。。。。。

  2. Alan  Reply to this comment

    试用成功,谢谢分享 :)

  3. 不使用插件支持Gravatar | Alan's World  Reply to this comment

    [...] 今天在underone的Blog看到如何不使用插件即可支持Gravatar这篇文章,马上试用,只需在Comment.php相应位置添加以下代码(添加代码前先禁用Gravatar插件),就可以支持Gravatar而不需试用任何插件: [...]

  4. candy  Reply to this comment

    很喜欢你做的模板~
    谢谢~
    头像插件也测试ok~

  5. AndyWxy  Reply to this comment

    学习鸟~ 赞下你的blog主题哈!

  6. 深蓝  Reply to this comment

    能出来树叶不

  7. underone  Reply to this comment

    能,出来了

  8. 痴情的猪  Reply to this comment

    基本全是不显示的。一个红X!

  9. underone  Reply to this comment

    我咋看全显示……

  10. sky  Reply to this comment

    看看

  11. sky  Reply to this comment

    怎么放到我自己的上面就不行呢

  12. underone  Reply to this comment

    我也不知道。。

  13. zblux  Reply to this comment

    试一下

  14. Francis  Reply to this comment

    $comment->comment_author_email

    者具有严重问题啊,应该修改成 get_comment_author_email()

  15. underone  Reply to this comment

    @Francis
    问题在哪里呢?我实际运用没有问题啊?
    那个……俺不懂PHP,指教下?

  16. 子游  Reply to this comment

    成功!

  17. 冰客  Reply to this comment

    貌似没这么多行啊

  18. mercy  Reply to this comment

    测试头像……

  19. plidezus  Reply to this comment

    测试下头像哈哈~

  20. underone  Reply to this comment

    头像没出来。。。

  21. momo  Reply to this comment

    测试~~~

  22. momo  Reply to this comment

    我看看

Leave a Reply ↓

收藏 & 分享

Powered by 17fav.com