WordPress で「この記事を書いた人」を作成


管理画面のプロフィールの情報を用いて「この記事を書いた人」を作成。

コーポレートサイトの場合、社長やスタッフのブログに利用できるのではないかと・・・。

まずは functions.php で次を入力し、管理画面のプロフィールページに項目を増やす。

function userSnMeta($sns)
{
	$sns['twitter']   = 'Twitter(twitter.com/以降)';
	$sns['facebook']  = 'Facebook(facebook.com/以降)';
	$sns['instagram'] = 'Instagram(instagram.com/以降)';
	return $sns;
}
add_filter('user_contactmethods', 'userSnMeta', 10, 1);

テンプレートで呼び出す場合は以下。

// プロフィール情報の入力有無で判定
if(!empty(get_the_author_meta('user_description')))
{
	the_author(); // ブログ上の表示名
	echo( get_avatar( get_the_author_meta( 'ID' ), 80 ) );	// アバター
	the_author_meta('user_url');	// webサイト
	the_author_meta('twitter');		// Twitter (functions.phpで追加した項目)
	the_author_meta('facebook');	// Facebook (functions.phpで追加した項目)
	the_author_meta('instagram');	// Instagram (functions.phpで追加した項目)
	the_author_meta('user_description');	// ユーザー情報
}