在 WordPress 2.5 中使用 Gravatar

03月 27th, 2008 Posted in WordPress |46 views

听说WordPress 2.5 已经将 Gravatar 集成了进来了.但是一直不知道怎么用.通过伟大的GOOGLE,终于在冰仔那里找到方法了.

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

<?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。

现在只有1个回复

Trackbacks & Pingbacks

我要留言