在做了新的皮肤之后,我一直在考虑是不是要打开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

, , ,

Bookmark and Share 17fav 收藏本文

引用地址:http://www.underone.com/2007/10/24/gravatar-no-plugin/

楼被抢了22层了


  1. adminReply to this comment Says @ 07-10-24 9:23 am (1)
  2. 留言就是个现成的例子。。。。。。。。

    underoneReply to this comment Says @ 07-10-24 9:32 am (2)
  3. 试用成功,谢谢分享 :)

    AlanReply to this comment Says @ 07-10-24 4:34 pm (3)
  4. 很喜欢你做的模板~
    谢谢~
    头像插件也测试ok~

    candyReply to this comment Says @ 07-11-12 12:44 am (4)
  5. 学习鸟~ 赞下你的blog主题哈!

    AndyWxyReply to this comment Says @ 07-11-20 7:36 pm (5)
  6. 能出来树叶不

    深蓝Reply to this comment Says @ 07-12-7 2:41 pm (6)
  7. 能,出来了

    underoneReply to this comment Says @ 07-12-7 4:12 pm (7)
  8. 基本全是不显示的。一个红X!

    痴情的猪Reply to this comment Says @ 08-01-10 1:25 am (8)
  9. 我咋看全显示……

    underoneReply to this comment Says @ 08-01-10 9:04 am (9)
  10. 看看

    skyReply to this comment Says @ 08-01-30 4:15 pm (10)
  11. 怎么放到我自己的上面就不行呢

    skyReply to this comment Says @ 08-01-30 4:29 pm (11)
  12. 我也不知道。。

    underoneReply to this comment Says @ 08-01-30 4:58 pm (12)
  13. 试一下

    zbluxReply to this comment Says @ 08-02-27 11:36 pm (13)
  14. $comment->comment_author_email

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

    FrancisReply to this comment Says @ 08-03-22 12:48 pm (14)
  15. @Francis
    问题在哪里呢?我实际运用没有问题啊?
    那个……俺不懂PHP,指教下?

    underoneReply to this comment Says @ 08-03-22 9:02 pm (15)
  16. 成功!

    子游Reply to this comment Says @ 08-03-24 11:26 am (16)
  17. 貌似没这么多行啊

    冰客Reply to this comment Says @ 08-05-15 6:23 am (17)
  18. 测试头像……

    mercyReply to this comment Says @ 08-06-10 1:21 pm (18)
  19. 测试下头像哈哈~

    plidezusReply to this comment Says @ 08-06-19 4:23 pm (19)
  20. 头像没出来。。。

    underoneReply to this comment Says @ 08-06-19 4:38 pm (20)
  21. 测试~~~

    momoReply to this comment Says @ 08-07-28 4:33 pm (21)
  22. 我看看

    momoReply to this comment Says @ 08-07-28 4:33 pm (22)

Trackbacks & Pingbacks

  • 不使用插件支持Gravatar | Alan's World

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

要说点啥就在这吧