之前我说过,一直在等WordPress 2.5,为的就是准备内置gravatar的支持。现在2.5RC1我装上了,如你们看到的,G7v5这个theme已经支持了gravatar。如果你也做好了为2.5升级的准备,并且想放弃任何一种gravatar插件,那么看下边儿……

首先需要打开后台的gravatar支持:进入后台(/wp-admin),选择settings—reading,将Avatar display选项选择为show Avatar,如图即可。

Avatar display

这个选项应该是默认开着的。接下来,当然你的theme应该还是不会有什么变化——当然了,缺一些代码。记住我们永远的学习对象:default theme,任何新的例子都应该在里面可以找到,我就是这么找到的……

如果已经升级到2.5,理论上……首先应该屏蔽之前使用的gravatar插件(不管哪种插件),同时在comments.php里删除之前添加的相关代码。完成以后就是个纯净的comments.php了,然后开始。

在想要显示gravatar的位置(我一般插入到<?php comment_text() ?>附近)插入如下代码:
<?php echo get_avatar( $comment, 32 ); ?>
32是你想要显示的头像的大小,数字自己改。完成这一步以后保存comments.php,刷新,肯定会出来个头像。
我不懂php,在之前的本地测试的theme中我是这么写的:
<?php echo get_avatar( get_comment_author_email(), '32' ); ?>
貌似也是正常的……(来路)。

但是这个头像显然没有任何修饰,对吧?但是css是万能滴!以上代码会输出一个.avatar的class。如果知道如何修改那就动手去。如果不知道……可以用任何文本编辑器打开theme目录中的style.css文件,在任何一行添加以下代码(这只是我使用的代码而已,牛人不要笑!):

.avatar {
 border: 1px solid #d3d3d3;
 background-color: #ffffff;
 padding: 2px;
 float: right;
 margin-top: 3px;
}

这事儿到此为止,应该就差不多了……如果你讨厌默认的那个默认头像,你也可以自定义。这么写:
<?php echo get_avatar( $comment, '32', 'http://www.你的网址.com/你的头像.jpg' ); ?>
我觉得该这么写……但是相对路径不知道怎么写才能搞出来,有知道的回复给我啊:)

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

, , ,

Bookmark and Share 17fav 收藏本文

引用地址:http://www.underone.com/2008/03/19/wordpress-25-gravatars-theme/

楼被抢了47层了


  1. adminReply to this comment Says @ 08-03-19 11:53 am (1)
  2. 好文, 受教了 :D

    AlanReply to this comment Says @ 08-03-19 12:38 pm (2)
  3. 啊, 真是太强悍了..

    锐风Reply to this comment Says @ 08-03-19 1:04 pm (3)
  4. 学习了。

    windReply to this comment Says @ 08-03-19 1:56 pm (4)
  5. 我只是想说说话!

    rebReply to this comment Says @ 08-03-19 2:47 pm (5)
  6. 学习了

    3dsdeskReply to this comment Says @ 08-03-19 4:35 pm (6)
  7. 收了!这两天我也去改改我用的那个主题。

    DreamcolorReply to this comment Says @ 08-03-19 4:35 pm (7)
  8. 8X8X 会了

    iakufReply to this comment Says @ 08-03-19 9:53 pm (8)
  9. .......................呵呵新主题什么时候出来

    iakufReply to this comment Says @ 08-03-19 9:54 pm (9)
  10. 个把礼拜吧……还在检查整理

    underoneReply to this comment Says @ 08-03-19 10:01 pm (10)
  11. 我是来测试头像的=。=

    evannanReply to this comment Says @ 08-03-21 12:27 pm (11)
  12. 这个也是

    evanWuReply to this comment Says @ 08-03-21 12:27 pm (12)
  13. 嗯,也來試試頭像。

    AmosReply to this comment Says @ 08-03-21 9:41 pm (13)
  14. 有两个问题:
    一,我设置了css,不知道为何不起作用。
    二,请问,发文的人在哪里设置自己的头像呀?

    Spring79Reply to this comment Says @ 08-03-22 9:42 am (14)
  15. 按上面代码,怎么把绝对地址换成相对地址呢?

    MichaelReply to this comment Says @ 08-03-22 12:25 pm (15)
  16. @Michael
    理论上应该是
    '< ?php bloginfo('stylesheet_directory'); ?>/images/xxx.jpg'
    这是相对当然theme的images目录

    @Spring79
    怎么不起作用法……你看我这里不是好的……是不是class的名字写错了?
    and,设置要在http://en.gravatar.com/
    这里

    underoneReply to this comment Says @ 08-03-22 9:20 pm (16)
  17. g7 v2的代码应该放在哪里?

    小谋深算Reply to this comment Says @ 08-03-22 9:27 pm (17)
  18. < ?php comment_text() ?>的旁边
    comments.php里

    underoneReply to this comment Says @ 08-03-22 9:53 pm (18)
  19. 我也是测试头像的。。 呵呵

    聿歆Reply to this comment Says @ 08-03-24 4:54 pm (19)
  20. 你们。。。
    都跑我这测个啥。。。。

    underoneReply to this comment Says @ 08-03-24 5:20 pm (20)
  21. 2.5支持ie6怎么样????

    z.Yleo77Reply to this comment Says @ 08-03-24 6:06 pm (21)
  22. 支持ie是theme的事情,和wodpress版本啥关系?

    tsianReply to this comment Says @ 08-03-24 6:12 pm (22)
  23. 同楼上。。。

    underoneReply to this comment Says @ 08-03-24 8:30 pm (23)
  24. 出现了~出现了~偶也RC了。。。

    JingReply to this comment Says @ 08-03-25 1:46 pm (24)
  25. 好神奇。。。为啥RC2了反而头像选项没了。。

    underoneReply to this comment Says @ 08-03-27 5:12 pm (25)
  26. 测试一下

    蓝染大人Reply to this comment Says @ 08-03-30 10:33 am (26)
  27. 学习了。

    陈默Reply to this comment Says @ 08-03-31 9:54 am (27)
  28. 同测

    justkReply to this comment Says @ 08-03-31 1:49 pm (28)
  29. 学习来了。。。HOHO

    levonReply to this comment Says @ 08-04-9 1:28 am (29)
  30. 为什么我照这个做了,在我的博客却不出现头像呀

    levonReply to this comment Says @ 08-04-10 9:32 pm (30)
  31. 我在你的博客试验了,出现了啊
    http://ilevon.cn/index.php/2008/04/09/create-a-link-page/

    underoneReply to this comment Says @ 08-04-10 10:01 pm (31)
  32. 没有啊,,,我没看到你的留言呀。晕咯,闹鬼啦

    levonReply to this comment Says @ 08-04-10 11:39 pm (32)
  33. 饿,,我犯了一个不该饭的错误。ADMIN的邮箱填错啦,哈哈
    笨死了我

    levonReply to this comment Says @ 08-04-11 12:00 am (33)
  34. @levon
    @underone
    有一种可能,如果你使用的是firefox,并且安装了ad block插件,gravatar会被屏蔽掉。
    关了ad block,就看见了。

    香草与叹息Reply to this comment Says @ 08-04-11 12:27 am (34)
  35. @levon
    hahaha

    underoneReply to this comment Says @ 08-04-11 9:20 am (35)
  36. 谢谢,学习了

    二手科学家Reply to this comment Says @ 08-04-12 1:55 am (36)
  37. 好多新东西 ,我都想换theme了

    interjcReply to this comment Says @ 08-04-18 11:31 am (37)
  38. 测试一下头像

    leoReply to this comment Says @ 08-05-1 3:26 pm (38)
  39. 对这个Gravatar还是不大明白...

    GxgzReply to this comment Says @ 08-05-31 8:54 pm (39)
  40. 学习啊了

    ameterReply to this comment Says @ 08-06-9 7:51 pm (40)
  41. 如何改默认的头像啊,没有账号的怎么办?

    iYangyiReply to this comment Says @ 08-06-11 10:13 pm (41)
  42. 要去gravatar.com注册啊

    underoneReply to this comment Says @ 08-06-11 10:33 pm (42)
  43. 不知道我的有没有 试试

    pigpotReply to this comment Says @ 08-07-29 2:38 pm (43)
  44. 哈,终于把我的头像加上去了。去看看我的。

    JoeReply to this comment Says @ 08-08-10 4:09 pm (44)

Trackbacks & Pingbacks

  • My Blog » Blog Archive » 升级到WordPress 2.5 RC1

    [...] 更标准的方法,谢谢Underone,如何让你的theme支持WordPress 2.5的Gravatars [...]

  • July's Blog » Blog Archive » 升级到WordPress 2.5 RC1

    [...] 关于内建Gravatars的使用:(以下内容转自Underone)如果已经升级到2.5,理论上……首先应该屏蔽之前使用的gravatar插件(不管哪种插件),同时在comments.php里删除之前添加的相关代码。完成以后就是个纯净的comments.php了,然后开始。 [...]

  • 沙风

    让我们一起来使用avatar...

    在写这篇日志前我从没使用过avatar。
    avatar在英文中是“化身”的意思,其实简单通俗地说就是“个人头像”。
    我想我们对个人头像一定很熟悉,这还用说吗?我们在论坛里使用个人头像...

  • July's Blog » 升级到WordPress 2.5 RC1

    [...] 关于内建Gravatars的使用:(以下内容转自Underone) 如果已经升级到2.5,理论上……首先应该屏蔽之前使用的gravatar插件(不管哪种插件),同时在comments.php里删除之前添加的相关代码。完成以后就是个纯净的comments.php了,然后开始。 [...]

要说点啥就在这吧