正在加载...

blog » WordPress / 软硬一本 » 如何让你的theme支持WordPress 2.5的Gravatars

如何让你的theme支持WordPress 2.5的Gravatars

之前我说过,一直在等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' ); ?>
我觉得该这么写……但是相对路径不知道怎么写才能搞出来,有知道的回复给我啊:)

Popularity: 31%

延展阅读

RSS 2.0 | leave a response | trackback

48 Responses

  1. Mar 19th, 2008 / 12:38 pm Reply to this comment Alan Says:

    好文, 受教了 :D

  2. Mar 19th, 2008 / 1:04 pm Reply to this comment 锐风 Says:

    啊, 真是太强悍了..

  3. Mar 19th, 2008 / 1:56 pm Reply to this comment wind Says:

    学习了。

  4. Mar 19th, 2008 / 2:47 pm Reply to this comment reb Says:

    我只是想说说话!

  5. Mar 19th, 2008 / 4:35 pm Reply to this comment 3dsdesk Says:

    学习了

  6. Mar 19th, 2008 / 4:35 pm Reply to this comment Dreamcolor Says:

    收了!这两天我也去改改我用的那个主题。

  7. Mar 19th, 2008 / 5:00 pm Reply to this comment My Blog » Blog Archive » 升级到WordPress 2.5 RC1 Says:

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

  8. Mar 19th, 2008 / 9:53 pm Reply to this comment iakuf Says:

    8X8X 会了

  9. Mar 19th, 2008 / 9:54 pm Reply to this comment iakuf Says:

    .......................呵呵新主题什么时候出来

  10. Mar 19th, 2008 / 10:01 pm Reply to this comment underone Says:

    个把礼拜吧……还在检查整理

  11. Mar 21st, 2008 / 12:27 pm Reply to this comment evannan Says:

    我是来测试头像的=。=

  12. Mar 21st, 2008 / 12:27 pm Reply to this comment evanWu Says:

    这个也是

  13. Mar 21st, 2008 / 9:03 pm Reply to this comment July's Blog » Blog Archive » 升级到WordPress 2.5 RC1 Says:

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

  14. Mar 21st, 2008 / 9:41 pm Reply to this comment Amos Says:

    嗯,也來試試頭像。

  15. Mar 22nd, 2008 / 9:42 am Reply to this comment Spring79 Says:

    有两个问题:
    一,我设置了css,不知道为何不起作用。
    二,请问,发文的人在哪里设置自己的头像呀?

  16. Mar 22nd, 2008 / 12:25 pm Reply to this comment Michael Says:

    按上面代码,怎么把绝对地址换成相对地址呢?

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

    @Michael
    理论上应该是
    '< ?php bloginfo('stylesheet_directory'); ?>/images/xxx.jpg'
    这是相对当然theme的images目录

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

  18. Mar 22nd, 2008 / 9:27 pm Reply to this comment 小谋深算 Says:

    g7 v2的代码应该放在哪里?

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

    < ?php comment_text() ?>的旁边
    comments.php里

  20. Mar 24th, 2008 / 4:54 pm Reply to this comment 聿歆 Says:

    我也是测试头像的。。 呵呵

  21. Mar 24th, 2008 / 5:20 pm Reply to this comment underone Says:

    你们。。。
    都跑我这测个啥。。。。

  22. Mar 24th, 2008 / 6:06 pm Reply to this comment z.Yleo77 Says:

    2.5支持ie6怎么样????

  23. Mar 24th, 2008 / 6:12 pm Reply to this comment tsian Says:

    支持ie是theme的事情,和wodpress版本啥关系?

  24. Mar 24th, 2008 / 8:30 pm Reply to this comment underone Says:

    同楼上。。。

  25. Mar 25th, 2008 / 1:46 pm Reply to this comment Jing Says:

    出现了~出现了~偶也RC了。。。

  26. Mar 27th, 2008 / 5:12 pm Reply to this comment underone Says:

    好神奇。。。为啥RC2了反而头像选项没了。。

  27. Mar 30th, 2008 / 10:33 am Reply to this comment 蓝染大人 Says:

    测试一下

  28. Mar 31st, 2008 / 12:55 am Reply to this comment 沙风 Says:

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

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

  29. Mar 31st, 2008 / 9:54 am Reply to this comment 陈默 Says:

    学习了。

  30. Mar 31st, 2008 / 1:49 pm Reply to this comment justk Says:

    同测

  31. Apr 9th, 2008 / 1:28 am Reply to this comment levon Says:

    学习来了。。。HOHO

  32. Apr 10th, 2008 / 9:32 pm Reply to this comment levon Says:

    为什么我照这个做了,在我的博客却不出现头像呀

  33. Apr 10th, 2008 / 10:01 pm Reply to this comment underone Says:

    我在你的博客试验了,出现了啊
    http://ilevon.cn/index.php/2008/04/09/create-a-link-page/

  34. Apr 10th, 2008 / 11:39 pm Reply to this comment levon Says:

    没有啊,,,我没看到你的留言呀。晕咯,闹鬼啦

  35. Apr 11th, 2008 / 12:00 am Reply to this comment levon Says:

    饿,,我犯了一个不该饭的错误。ADMIN的邮箱填错啦,哈哈
    笨死了我

  36. Apr 11th, 2008 / 12:27 am Reply to this comment 香草与叹息 Says:

    @levon
    @underone
    有一种可能,如果你使用的是firefox,并且安装了ad block插件,gravatar会被屏蔽掉。
    关了ad block,就看见了。

  37. Apr 11th, 2008 / 9:20 am Reply to this comment underone Says:

    @levon
    hahaha

  38. Apr 12th, 2008 / 1:55 am Reply to this comment 二手科学家 Says:

    谢谢,学习了

  39. Apr 18th, 2008 / 11:31 am Reply to this comment interjc Says:

    好多新东西 ,我都想换theme了

  40. May 1st, 2008 / 3:26 pm Reply to this comment leo Says:

    测试一下头像

  41. May 7th, 2008 / 2:30 pm Reply to this comment July's Blog » 升级到WordPress 2.5 RC1 Says:

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

  42. May 31st, 2008 / 8:54 pm Reply to this comment Gxgz Says:

    对这个Gravatar还是不大明白...

  43. Jun 9th, 2008 / 7:51 pm Reply to this comment ameter Says:

    学习啊了

  44. Jun 11th, 2008 / 10:13 pm Reply to this comment iYangyi Says:

    如何改默认的头像啊,没有账号的怎么办?

  45. Jun 11th, 2008 / 10:33 pm Reply to this comment underone Says:

    要去gravatar.com注册啊

  46. Jul 29th, 2008 / 2:38 pm Reply to this comment pigpot Says:

    不知道我的有没有 试试

  47. Aug 10th, 2008 / 4:09 pm Reply to this comment Joe Says:

    哈,终于把我的头像加上去了。去看看我的。

  48. Jan 3rd, 2011 / 9:45 pm Reply to this comment liang Says:

    学习了,呵呵

Leave a Reply