WordPress 文章页作者信息 get_the_author() 和 get_the_author_meta()

在WordPress中,获取当前文章的作者信息可以使用get_the_author()函数。这个函数返回当前文章的作者用户名。如果你需要获取更多作者的信息,比如邮箱或者用户的其他字段,你可以使用get_userdata()函数。

以下是一些示例代码:

获取当前文章的作者用户名:

echo get_the_author();

获取当前文章作者的邮箱地址:

$author_id = get_the_author_meta('ID');
$author_email = get_the_author_meta('user_email', $author_id);
echo $author_email;

获取当前文章作者的所有元数据:

$author_id = get_the_author_meta('ID');
print_r(get_userdata($author_id));

在循环中获取多篇文章的作者信息:

if (have_posts()) {
    while (have_posts()) {
        the_post();
        echo 'Author: ' . get_the_author() . '<br>';
    }
}

在这些例子中,get_the_author_meta()函数用于获取作者的特定元数据,其中第二个参数是可选的,如果不提供,则默认为当前文章的作者。如果你需要获取其他用户的信息,你可以通过用户的ID来获取。

收藏
评论
打赏
WordPress 函数 add_option()、get_option() 和 update_option()
上一篇
WordPress 用户元信息 get_user_meta() 和 update_user_meta()
下一篇

0 条评论

像素鱼丸
81329 阅读
136 发布
3 收藏
动态
Mirage 主题 v2.52.0 发布
Mighty 企业主题 v1.9.0 发布
MirageV 主题 v2.6.4 发布
MirageV 主题 v2.6.0 发布
BotV 插件 v1.7.0 发布
FishV 主题 v1.14 发布
LandV 企业主题 v2.6.0 发布
MirageV-App 小程序 v1.2.2 发布
生成中...
真诚赞赏,手留余香
登录
注册
重置密码