正在加载...

blog » WordPress / 软硬一本 » 如何不使用插件即可支持Gravatar

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

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

Popularity: 22%

延展阅读

RSS 2.0 | leave a response | trackback

23 Responses

  1. Oct 24th, 2007 / 9:32 am Reply to this comment underone Says:

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

  2. Oct 24th, 2007 / 4:34 pm Reply to this comment Alan Says:

    试用成功,谢谢分享 :)

  3. Oct 24th, 2007 / 5:22 pm Reply to this comment 不使用插件支持Gravatar | Alan's World Says:

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

  4. Nov 12th, 2007 / 12:44 am Reply to this comment candy Says:

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

  5. Nov 20th, 2007 / 7:36 pm Reply to this comment AndyWxy Says:

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

  6. Dec 7th, 2007 / 2:41 pm Reply to this comment 深蓝 Says:

    能出来树叶不

  7. Dec 7th, 2007 / 4:12 pm Reply to this comment underone Says:

    能,出来了

  8. Jan 10th, 2008 / 1:25 am Reply to this comment 痴情的猪 Says:

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

  9. Jan 10th, 2008 / 9:04 am Reply to this comment underone Says:

    我咋看全显示……

  10. Jan 30th, 2008 / 4:15 pm Reply to this comment sky Says:

    看看

  11. Jan 30th, 2008 / 4:29 pm Reply to this comment sky Says:

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

  12. Jan 30th, 2008 / 4:58 pm Reply to this comment underone Says:

    我也不知道。。

  13. Feb 27th, 2008 / 11:36 pm Reply to this comment zblux Says:

    试一下

  14. Mar 22nd, 2008 / 12:48 pm Reply to this comment Francis Says:

    $comment->comment_author_email

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

  15. Mar 22nd, 2008 / 9:02 pm Reply to this comment underone Says:

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

  16. Mar 24th, 2008 / 11:26 am Reply to this comment 子游 Says:

    成功!

  17. May 15th, 2008 / 6:23 am Reply to this comment 冰客 Says:

    貌似没这么多行啊

  18. Jun 10th, 2008 / 1:21 pm Reply to this comment mercy Says:

    测试头像……

  19. Jun 19th, 2008 / 4:23 pm Reply to this comment plidezus Says:

    测试下头像哈哈~

  20. Jun 19th, 2008 / 4:38 pm Reply to this comment underone Says:

    头像没出来。。。

  21. Jul 28th, 2008 / 4:33 pm Reply to this comment momo Says:

    测试~~~

  22. Jul 28th, 2008 / 4:33 pm Reply to this comment momo Says:

    我看看

  23. Apr 7th, 2009 / 5:40 pm Reply to this comment 神兽 Says:

    这就去试试。

Leave a Reply