在 WordPress 2.5 中使用 Gravatar

2

听说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。

暧味日志

2 Responses

  1. ukuru-blog says:

    我先在这试试,呆会再修改我的模版。学习了。

Leave a Reply

© 2007-2010 猫言猫语. All rights reserved. Powered by WordPress. 17 queries in 0.112 seconds.
Proudly designed by Theme Junkie.