说明
模板标签the_author_meta显示用户的元数据。如果该标签用在主循环(loop)中,不必指定用户ID值,标签所显示的就是当前文章作者的元数据。如果该标签用在WordPress主循环(loop)外,需要指定用户ID值。
注意:如果需要返回(不显示)用户信息,请使用get_the_author_meta()。
用法
<?php the_author_meta( $field, $userID ); ?>
参数
$field
(字符串)将要显示的用户信息的字段名称。有效值包括:
-
user_login
-
user_pass
-
user_nicename
-
user_email
-
user_url
-
user_registered
-
user_activation_key
-
user_status
-
display_name
-
nickname
-
first_name
-
last_name
-
description
-
jabber
-
aim
-
yim
-
user_level
-
user_firstname
-
user_lastname
-
user_description
-
rich_editing
-
comment_shortcuts
-
admin_color
-
plugins_per_page
-
plugins_last_view
-
ID
$userID
(整数)如果指定用户ID字段,该函数可显示该用户的相关字段信息。
示例
显示用户的AIM登录名
显示用户的AIM(AOL即时通讯账号)字段的值。
<p>This author's AIM address is <?php the_author_meta('aim'); ?></p>
显示用户email地址
显示ID为25的用户的电子邮件地址。
<p>The email address for user id 25 is <?php the_author_meta('user_email',25); ?></p>
进阶用法
有些扩展方法可以在用户注册或管理用户时添加额外选项,从而在wp_usermeta中(其中wp_是你的数据库前缀)新增一个值。这里假设我们要增加一个Twitter ID选项,使扩展方法将meta_key的值设为"twitter",meta_value的值设为"wordpress",那么
<p>This author's Twitter name is <?php the_author_meta('twitter'); ?></p>
将返回
<p>This author's Twitter name is wordpress</p>
历史记录
始见于 WordPress 2.8.0
源文件
the_author_meta() 位于 wp-includes/author-template.php中。
发表新评论