テンプレートタグ/the author meta

出典: WordPress Codex 日本語版

the_author_metaテンプレートタグを使えば、あるユーザーが持つメタデータから好きなものを表示することができます。このタグをループの中で使った場合、ユーザーIDを指定する必要はありません。表示されるデータは現在の投稿の作者のものになります。ループの外で使われた場合、ユーザーIDを指定する必要があります。

注: この情報を戻り値(表示しないPHPの変数)として使用したい場合は、get_the_author_meta()/en を使ってください。

使用法

<?php the_author_meta( $field, $userID ); ?>

パラメータ

$field 
(string) 表示したいデータのフィールド名。有効な値は以下の通りです。
  • 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 
(integer) これが指定されると、このIDを持つユーザーの情報が表示されます。

投稿作成者の AIM アカウント名を表示する

投稿作成者の AIM (AOL Instant Messenger アカウント) フィールドを表示します。

<p>この著者の AIM アカウントは <?php the_author_meta('aim'); ?> です。</p>

特定のユーザーのメールアドレスを表示する

ユーザー ID 25のメールアドレスを表示します。

<p>ID 25のユーザーのアドレスは <?php the_author_meta('user_email',25); ?> です。</p>

高度な使い方

プラグインを使ってユーザー登録時や管理画面から wp_usermeta(wp_ はデータベース接頭辞)に新しい値を追加することもできます。以下は、プラグインが meta_key のキーを "twitter" と設定し、その meta_value が "wrodpress" となっている場合の例です。

<p>投稿者の Twitter ID: <?php the_author_meta('twitter'); ?></p>

と書くと、

<p>投稿者の Twitter ID: wordpress</p>

のように表示されます。

変更履歴

  • 2.8 : 新規テンプレートタグ

ソースファイル

the_author_meta()wp-includes/author-template.php 内にあります。

the_author, the_author_link, the_author_posts, the_author_posts_link, wp_list_authors, wp_dropdown_users, the_author_meta



最新英語版: WordPress Codex » Template Tags/the_author_meta最新版との差分

他の言語