返回介绍

the_author_meta()

发布于 2017-09-11 10:32:21 字数 4023 浏览 1092 评论 0 收藏 0

the_author_meta( string $field = '',  int $user_id = false )

Outputs the field from the user’s DB object. Defaults to current post’s author.


description


参数

$field

(string) (Optional) selects the field of the users record.

Default value: ''

$user_id

(int) (Optional) User ID.

Default value: false


源代码

File: wp-includes/author-template.php

function the_author_meta( $field = '', $user_id = false ) {
	$author_meta = get_the_author_meta( $field, $user_id );

	/**
	 * The value of the requested user metadata.
	 *
	 * The filter name is dynamic and depends on the $field parameter of the function.
	 *
	 * @since 2.8.0
	 *
	 * @param string $author_meta The value of the metadata.
	 * @param int    $user_id     The user ID.
	 */
	echo apply_filters( "the_author_{$field}", $author_meta, $user_id );
}

更新日志

Versiondescription
2.8.0Introduced.

相关函数

Uses

  • wp-includes/plugin.php: apply_filters()
  • wp-includes/author-template.php: get_the_author_meta()
  • wp-includes/author-template.php: the_author_{$field}

Used By

  • wp-includes/deprecated.php: the_author_icq()
  • wp-includes/deprecated.php: the_author_yim()
  • wp-includes/deprecated.php: the_author_msn()
  • wp-includes/deprecated.php: the_author_aim()
  • wp-includes/deprecated.php: the_author_url()
  • wp-includes/deprecated.php: the_author_ID()
  • wp-includes/deprecated.php: the_author_description()
  • wp-includes/deprecated.php: the_author_login()
  • wp-includes/deprecated.php: the_author_firstname()
  • wp-includes/deprecated.php: the_author_lastname()
  • wp-includes/deprecated.php: the_author_nickname()
  • wp-includes/deprecated.php: the_author_email()
  • Show 7 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 2You must log in to vote on the helpfulness of this note Contributed by Codex

    Display a User Email Address
    Displays the email address for user ID 25.

    
    <p><?php printf( __( 'The email address for user id 25 is %s', 'textdomain' ), get_the_author_meta( 'user_email',25 ) ); ?></p>
    
  2. Advanced Uses
    A plugin may add an additional field in the registration or manage users, which adds a new value in the wp_usermeta (where wp_ is your data base prefix. For this example we will use a Twitter ID if a plugin set meta_key value to “twitter” and meta_value to “wordpress” then

    
    <p><?php printf( __( 'This author’s Twitter name is %s', 'textdomain' ), get_the_author_meta( 'twitter' ) ); ?></p>
    

    would return:

    This author’s Twitter name is WordPress

    And if you actually want to show the Author description using this function you can just do:

    <?php $authorDesc = the_author_meta('description'); echo $authorDesc; ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文