$authordata
在设置第一个帖子之前不可用(在第一个帖子之前the_post();
).
但是您需要的所有数据都已经存在于作者存档中:inget_queried_object()
.
这是一个WP_User Object
在作者档案中。
print \'<pre>\' . htmlspecialchars( print_r( get_queried_object(), TRUE ) ) . \'</pre>\';
结果:
WP_User Object
(
[data] => stdClass Object
(
[ID] => 2
[user_login] => toscho
[user_pass] => $P$BO6.B4TIhxnKspIlxXHJCqa.M4I3v01
[user_nicename] => toscho
[user_email] => [email protected]
[user_url] =>
[user_registered] => 2011-12-25 15:20:12
[user_activation_key] =>
[user_status] => 0
[display_name] => toscho
)
[ID] => 2
[caps] => Array
(
[author] => 1
)
[cap_key] => test_capabilities
[roles] => Array
(
[0] => author
)
[allcaps] => Array
(
[upload_files] => 1
[edit_posts] => 1
[edit_published_posts] => 1
[publish_posts] => 1
[read] => 1
[level_2] => 1
[level_1] => 1
[level_0] => 1
[delete_posts] => 1
[delete_published_posts] => 1
[author] => 1
)
[filter] =>
)
因此,这将打印当前作者的第一个角色:
! empty ( get_queried_object()->roles )
and print ucfirst( get_queried_object()->roles[0] );