在 WordPress 2.5 中使用 Gravatar

WordPress 去年收购了 Gravatar 公司,并在 WordPress 2.5 中集成了这款插件;那么,你知道如何修改你的WordPress 主题,来显示头像么?

你需要在模板中添加的,只有这几行代码:

<?php if (function_exists(‘get_avatar’)) { ?>
<div class=“gravatar”><?php echo get_avatar(get_comment_author_email(),‘64′); ?></div>
<?php } ?>
甚至你可以去掉这个 div 容器,干脆一行代码:

<?php if (function_exists(‘get_avatar’)) { echo get_avatar(get_comment_author_email(),‘64′); } ?>
稍微解释一下,用来显示 Gravatar 头像的函数是 get_avatar()get_comment_author_email() 放在留言 loop 中得到留言者的 email 地址,这个很关键,Gravatar 头像基本上全靠这个 email 了,后面的 ‘64′ 表示头像显示的宽度、高度均为 64px,最大为 80px。

OK 了啦。测试效果请在下面留言哦~~前提是你已经拥有了 Gravatar 的头像。

原文:http://hellobmw.com/archives/using-gravatar-in-wordpress-25.html

17fav 收藏本文

Tags: ,

Leave a Reply