WordPress:Using Gravatars
What is a Gravatar?[ ]
Gravatar是什么?[ ]
Gravatars are Globally Recognized Avatars. An avatar or gravatar is an icon, or representation, of a user in a shared virtual reality, such as a forum, chat, website, or any other form of online community in which the user(s) wish to have something to distinguish themselves from other users. Created by Tom Werner, gravatars make it possible for a person to have one avatar across the entire web. Avatars are usually an 80px by 80px image that the user will create themselves.
Gravatars是全球公认的Avatars。一个avatar或者gravatar是一个图标或者图像,是用户在虚拟世界,如论坛,聊天,网页,或者其它形式的在线团体,想要将自己与其它用户区别开来的标记。Garatars 是由Tom Werner创建的,gravatars能使人们将一个avatar在整个网页上扩展。Avatars通常是一个80px 乘 80px的图像,用户可以自己创建。
frame|right|Gravatars in blog post commentsA Gravatar is essentially the same thing, but they are all hosted on a single server and are called up by encrypting the users' email address via the MD5 algorithm. So instead of having one avatar on one forum you visit, and another at a blog you visit, you could have the same avatar at both.
frame|right|博客文章评论中的GravatarsGravatar本质上是同样的内容,但是是在一个单一的服务器上托管的,而且通过MD5算法,加密用户的电子邮件地址,调用的。因此不止将一个avatar放到你要访问的论坛上,将另一个avatar放到你要访问的博客上,你可以将同一个avatar放在这两个位置。
Gravatars can easily be used within WordPress with the Gravatar WordPress Plugin or added manually in the index.php, comments.php and comments-popup.php template files.
拥有Gravatar WordPress插件,能够轻易地在WordPress内部使用Gravatars,或者动手将Gravatars添加到index.php, comments.php和 comments-popup.php 模板文件中。
How a Gravatar is Constructed[ ]
Gravatar是结构是怎样的[ ]
A Gravatar is a dynamic image resource that is requested from a server. The request URL is presented here, broken into its segments. The URL always begins with:
Gravatar是动态的图像资源,可以从服务器中得到。需要的URL呈现在这里,分割成几段。URL通常开始是:
http://www.gravatar.com/avatar.php?
http://www.gravatar.com/avatar.php?
A mandatory parameter named gravatar_id follows this. Its value is the hexadecimal MD5 hash of the requested users' email address with all whitespace trimmed. The value is case insensitive.
一个称为gravatar_id的命令参数遵循了这一点。数值是被请求的用户的电子邮件地址,但是去除了空格,十六进制的MD5 hash。参数值区分大小写。
gravatar_id=279aa12c3326f87c460aa4f31d18a065
gravatar_id=279aa12c3326f87c460aa4f31d18a065
An optional rating parameter may follow with a value of [ G | PG | R | X ] which determines the highest rating (inclusive) that will be returned.
可选择的rating参数后面可能有参数值[ G | PG | R | X ],这个参数值决定了返回的最高级别(包含的)。
&rating=R
&rating=R
Gravatar offers a rate checking service so you can determine your rate.
Gravatar提供了rate checking 服务,因此你可以决定你的rate。
An optional size parameter may follow that specifies the desired width and height of the Gravatar. Valid values are from 1 to 80 inclusive. Any size other than 80 will cause the original Gravatar image to be downsampled using bicubic resampling before output.
可选择的大小参数可能会遵循规定的Gravatar的宽度和高度。有效的参数值包括1到80。除了80外的任何的大小会导致原始的Gravatar图像downsampled,使用bicubic resampling才能够产出。
&size=40
&size=40
An optional default parameter may follow that specifies the full URL, encoded URL, protocol included, of a GIF, JPEG, or PNG image that should be returned if either the requested email address has no associated gravatar, or that Gravatar has a rating higher than is allowed by the rating parameter.
可选择的默认参数可能遵循规定的完整的URL,编码的URL,包含的协议,如果被请求的电子邮件地址没有相关的gravatar或者Gravatar拥有的rating比rating参数中规定的要高,会返回GIF, JPEG, 或者 PNG 图像。
&default=http%3A%2F%2Fwww.somesite.com%2Fsomeimage.jpg
&default=http%3A%2F%2Fwww.somesite.com%2Fsomeimage.jpg
An optional border parameter may follow that specifies the hexadecimal value of a 1px border to be overlaid on the Gravatar. The supplied value may be either the full six character hex string (e.g. FF0000 for red) or the abbreviated three character hex string (e.g. F00 for red).
可选择的border参数可能遵循Gravatar覆盖的1px border的十六进制数值。提供的参数值可能是完整的六位字符的十六进制字符串(例如FF0000表示红色)或者简化的三个字符的十六进制字符串(例如F00表示红色)。
&border=FF0000
&border=FF0000
Using Gravatars in WordPress[ ]
在WordPress中使用Gravatars[ ]
frame|right|An example of a GravatarFor most people, encrypting an email address with MD5 is no easy task, most of the time requiring PHP or other form of scripting. Several WordPress Plugins have been created to help with this task, such as the Gravatar.com Plugin and Gravatars2 Enhanced Caching Plugin.For information on using and installing those WordPress Plugins, see the Plugin's documentation.
frame|right| Gravatar的一个例子对于大多数人而言,用MD5加密电子邮件并不是简单的任务,大多数时候,需要PHP或者其它形式的脚本。已经创建了几个WordPress 插件帮助完成这个任务,例如Gravatar.com 插件 和 Gravatars2 提升的隐藏插件。关于安装和使用这些WordPress插件的信息,请看看插件文档。
As of WordPress 2.5, Gravatars are built-in and require no additional Plugins for basic usage and management.
从WordPress2.5版本开始,Gravatars是内置的而且不需要额外的插件,简单地使用和管理Gravatars。
WordPress 2.5 marries theme authors and casual WordPress users together with support for Gravatars in the WordPress Administration Panels. Theme authors have an option to include Gravatars in their designs, and are recommended to do so. WordPress users can easily control their Gravatar usage in the Settings > Discussion Administration Panel.
WordPress2.5版本与主题作者,临时的WordPress用户,WordPress管理面板中的Gravatars支持相结合。主题作者拥有一个选项,将Gravatars包含在设计中,而且也得到建议,可以这样做。WordPress可以在设置 >讨论管理面板中轻易地控制Gravatar的用法。
WordPress users can change: WordPress的用户可以更改:
- Whether Avatars (aka, Gravatars) are displayed or not.
- 是否显示Avatars (aka, Gravatars)。
- Which rating of Avatars are shown.
- 显示的Avatars是哪个rating。
Theme Support for WordPress 2.5[ ]
关于WordPress2.5的主题支持[ ]
The function to add Gravatars to your theme is called: get_avatar
. The function returns a complete image HTML tag of the Avatar.
将Gravatars添加到你的主题的函数,称为:get_avatar
。这个函数返回了Avatar的HTML标签完整的图像。
The function is called as follows:
调用的函数是:
<?php echo get_avatar( $id_or_email, $size = '96', $default = '<path_to_url>' ); ?>
<?php echo get_avatar( $id_or_email, $size = '96', $default = '<path_to_url>' ); ?>
The parameters are: 参数是:
- id_or_email (required): Author’s User ID (an integer or string), an E-mail Address (a string) or the comment object from the comment loop. Note: with most comment templates you can use
$comment
here, in order to display the gravatar of the commenter. In other templates, you can useget_the_author_id()
here.
- id_or_email (必需的):作者的用户ID(一个整数或者字符串),一个电子邮件地址(一个字符串)或者来自评论loop的评论object。注: 拥有大多数评论模板,你可以在这里使用
$评论
,以显示评论员的gravatar。在其它模板中,你可以在这里使用get_the_author_id()
。
- size (optional): Avatar display size (max is 512).
- 大小 (可选择的):Avatar显示大小(最大是512)。
- default (optional): Absolute location of the default avatar to use (used when the person has no email address associated with them). If this is left blank then the gravatar you see here will be used as the default avatar.
- 默认 (可选择的):使用的默认avatar的绝对路径(当人们没有与gravatar相关的电子邮件地址时,就会使用这个绝对路径)。如果这个路径是空白的,那么你看到的gravatarhere会作为默认avatar来使用。
Some things to note here:
这里要注意的一些事项:
- The default Avatar size is 96x96 if you do not set the size using the size paramater.
- 如果你没有使用大小参数设置大小,默认的Avatar大小是96x96。
- The default Avatar is Gravatar
- 默认Avatar是Gravatar
- The Avatars will show only if the user allows them in the WP Admin Panel (enabled by default).
- 用户在WP管理面板中允许Avatars(默认是允许的)的时候,Avatar才会显示。
- The Avatars will only show based on the rating the user has selected in the WordPress Administration Panels.
- Avatars会根据用户在WordPress管理面板上选择的rating显示。
Code output:
代码输出:
The default output is when using the above function is listed below. Various classes are applied to img element to help you with element styling.
使用上述函数列在下面时,默认的输出。Img元素上应用了不同的classes,帮助你设计元素。
<img alt='' src='http://gravatarurl_or_default' class='avatar avatar-$size' height='$size' width='$size' />
<img alt='' src='http://gravatarurl_or_default' class='avatar avatar-$size' height='$size' width='$size' />
If the gravatar reverts to the default image due to a lack of an e-mail address (i.e. a pingback or trackback), whether you have specified a default or not, the img
element will also be given a CSS class of avatar-default
.
如果因为缺少电子邮件地址,gravatar返回到默认图像(例如pingback 或者trackback),不管你有没有规定默认设置,img
也会得到code>avatar-default的CSS class。
Backwards Compatibility[ ]
向后兼容[ ]
If you wish to develop a WordPress Theme with Avatars for 2.5 and below, add a check for the Gravatar function to the code:
如果你想使用Avatars2.5版本以及更低的版本,开发WordPress主题,向代码添加Gravatar函数:
if (function_exists('get_avatar')) { echo get_avatar($email); } else { //alternate gravatar code for < 2.5 $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id= " . md5($email) . "&default=" . urlencode($default) . "&size=" . $size; echo "<img src='$grav_url'/>"; }
if (function_exists('get_avatar')) { echo get_avatar($email); } else { //alternate gravatar code for < 2.5 $grav_url = "http://www.gravatar.com/avatar.php?gravatar_id= " . md5($email) . "&default=" . urlencode($default) . "&size=" . $size; echo "<img src='$grav_url'/>"; }
Gravatar.com Plugin[ ]
Gravatar.com插件[ ]
The Gravatar.com Plugin from Gravatar is the official Plugin for handling Gravatars.
来自Gravatar的Gravatar.com 插件是处理Gravatar的官方插件。
To use it:
怎样使用这个插件:
- Install and activate the Plugins.
- 安装并且激活插件。
- Place the
<?php gravatar(); ?>
function tag into the WordPress template file within the WordPress Loop within an HTML image tag:
- 将
<?php gravatar(); ?>
函数标签放入HTML图像标签内的WordPress Loop内的WordPress模板文件中:
<img src="<?php gravatar(); ?>" alt="Gravatar" />
<img src="<?php gravatar(); ?>" alt="Gravatar" />
For more information on using and installing the Gravatars.com WordPress Plugin, visit the Gravatars site.
关于更多的使用和安装Gravatars.com WordPress插件的信息,请访问Gravatars 站点。
Customizing Your Gravatars[ ]
自定义你的 Gravatars[ ]
There are several settings to customize the Gravatars. The setting parameters are:
有几种设置可以自定义Gravatars。设置参数是:
<?php gravatar("rating", size, "default", "border"); ?>
<?php gravatar("rating", size, "default", "border"); ?>
- rating
- The highest rating of Gravatar to be shown. The values are G, PG, R, and X. Showing only Gravatar's with a rating higher than PG can be accomplished with the following code:
;rating:显示的Gravatar的最高的rating。参数值是G, PG, R, and X。只用高于PG的rating显示Gravatar's,可以通过下面的代码实现:
<?php gravatar("PG"); ?>
<?php gravatar("PG"); ?>
- size
- Gravatar size is 80px by 80px by default. To change the sie, change the size value, keeping the size square, such as 80px by 80px:
;大小:Gravatar大小默认是80px 乘80px。更改大小,更改大小参数值,保存大小square,例如80px乘80px:
<?php gravatar("PG", 80); ?>
<?php gravatar("PG", 80); ?>
- default
- If a user is not registered with Gravatars or another compatible Avatar service, a default image will be shown. You can override this with a custom image as a PNG, JPG, or GIF.
;默认:如果用户没有注册Gravatar或者其它兼容的Avatar服务,会显示默认图像。你可以用一个自定义的图像,如PNG, JPG, 或者GIF覆盖默认图像。
<?php gravatar("PG",40,"/images/no_gravatar.gif"); ?>
<?php gravatar("PG",40,"/images/no_gravatar.gif"); ?>
- border
- To add a border, use the border function. It will add a 1px wide border around the Gravatar of the color that you choose. By default there is no border. The following is an example of a Gravatar that will be no higher than a PG rating, be 40px by 40px, have a default image if no Gravatar is present, and have a 1px red border:
;边框:要添加边框,需要使用border函数,就会在Gravatar的周围,添加1px宽度的边框,边框颜色是你选择的颜色。默认情况下,没有边框。下面是Gravatar的一个例子,不高于PG rating,40px 乘 40px,如果没有呈现Gravatar,就会有一个默认图像,而且有一个1px的红色边框。
<?php gravatar("PG",40,"/images/no_gravatar.gif","FF0000"); ?>
<?php gravatar("PG",40,"/images/no_gravatar.gif","FF0000"); ?>
Resources[ ]
资源[ ]
- Gravatar
- WordPress Plugins
- oBeattie : Meet the Gravatars
- Gravatars Implement Page
- Gravatar Signup Plugin
- Live Gravatar Preview Hack
- Gravatars & WordPress 2.5
- Add Gravatar Support to Your WordPress Comments