WordPress函数文档get_avatar()

获取用户的头像信息 描述 Retrieve the avatar for a user who provide…

获取用户的头像信息

描述

Retrieve the avatar for a user who provided a user ID or email address. Most commonly used in the comments section.

This function is pluggable, however plugin authors wishing to change the gravatar output should use the get_avatar filter instead, for compatibility purposes.

This function will not return an avatar if “Show Avatars” is unchecked in Settings > Discussion.

用法

 <?php echo get_avatar$id_or_email$size$default$alt$args ); ?> 

参数

id_or_email

(integer/string/object) (必填) 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 within The Loop (for WordPress 2.7 and lower), you can use get_the_author_id() (deprecated in WordPress 2.8). For WordPress 2.8 and up, please use get_the_author_meta( 'ID' ).

默认值: None

size

(integer) (可选) Size of Gravatar to return (max is 512).

默认值: 96

default

(string) (可选) url for an image, defaults to the “Mystery Man”.

默认值:

alt

(string) (可选) Alternate text for the avatar.

默认值: false

args

(array) (可选) Arguments to return instead of the default arguments.

默认值: null

$args

Note: If you change the $defaults in your get_avatar using $new_defaults, you must declare the $new_defaults BEFORE you call get_avatar, otherwise, they won’t take effect.

Default values:

size

(int) (可选) Height and width of the avatar image file in pixels.

默认值: 96′

height

(int) (可选) Display height of the avatar in pixels.

默认值: Defaults to $size.

width

(int) (可选) Display width of the avatar in pixels.

默认值: Defaults to $size.

default

(string) (可选) URL for the default image or a default type. Accepts ‘404’ (return a 404 instead of a default image), ‘retro’ (8bit), ‘monsterid’ (monster), ‘wavatar’ (cartoon face), ‘indenticon’ (the “quilt”), ‘mystery’, ‘mm’, or ‘mysterman’ (The Oyster Man), ‘blank’ (transparent GIF), or ‘gravatar_default’ (the Gravatar logo).

默认值: Default is the value of the ‘avatar_default’ option, with a fallback of ‘mystery’.

force_default

(bool) (可选) Whether to always show the default image, never the Gravatar.

默认值: false.

rating

(string) (可选) What rating to display avatars up to. Accepts ‘G’, ‘PG’, ‘R’, ‘X’, and are judged in that order.

默认值: Default is the value of the ‘avatar_rating’ option.

scheme

(string) (可选) URL scheme to use. See set_url_scheme() for accepted values.

默认值:

class

(array|string) (可选) Array or string of additional classes to add to the <img> element.

默认值: null

force_display

(bool) (可选) Whether to always show the avatar – ignores the show_avatars option.

默认值: false

extra_attr

(string) (可选) HTML attributes to insert in the IMG element. Is not sanitized.

默认值: empty.

返回值

string|false 

An img element for the user’s avatar or false on failure. The function does not output anything; you have to echo the return value.

示例

For comments:

For a post’s author, in The Loop:

For a random email address:

注意

  • 使用到 the get_avatar 过滤器 to 过滤器 the returned string.
  • This function is pluggable and so can be overridden by plugins and themes. The default functionality cannot be relied upon in these cases.

源文件

get_avatar() 函数的代码位于 wp-includes/pluggable.php.

相关

  • Using Gravatars
  • 原文:http://codex.wordpress.org/Function_Reference/get_avatar
类别:WordPress函数文档

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT