Php 从帖子id获取作者信息
或者甚至是文章id中的作者id。我试图在单个文章页面的侧栏中(在文章循环之外)返回作者元(作者页面链接和化身)。最好的方法是什么?我正在使用一个自定义函数(见下文)返回post id,但不确定下一步调用哪个函数Php 从帖子id获取作者信息,php,wordpress,Php,Wordpress,或者甚至是文章id中的作者id。我试图在单个文章页面的侧栏中(在文章循环之外)返回作者元(作者页面链接和化身)。最好的方法是什么?我正在使用一个自定义函数(见下文)返回post id,但不确定下一步调用哪个函数 function this_post_id() { global $wp_query; $thePostID = $wp_query->post->ID; return $thePostID; } 我想出来了 <?php $author_id=$post-
function this_post_id() {
global $wp_query;
$thePostID = $wp_query->post->ID;
return $thePostID;
}
我想出来了
<?php $author_id=$post->post_author; ?>
<img src="<?php the_author_meta( 'avatar' , $author_id ); ?> " width="140" height="140" class="avatar" alt="<?php echo the_author_meta( 'display_name' , $author_id ); ?>" />
<?php the_author_meta( 'user_nicename' , $author_id ); ?>
“width=“140”height=“140”class=“avatar”alt=”“/>
如果您希望它位于循环之外,请使用以下代码
<?php
$author_id = get_post_field ('post_author', $cause_id);
$display_name = get_the_author_meta( 'display_name' , $author_id );
echo $display_name;
?>
$字段
参数的有效值包括:
- 行政色彩
- 瞄准
- 评论快捷方式
- 描述
- 显示名称
- 名字
- 身份证
- 叽叽喳喳
- 姓
- 绰号
- 插件\u最后\u视图
- 每个页面的插件
- 丰富的编辑
- 语法突出显示
- 用户\激活\密钥
- 用户描述
- 用户电子邮件
- 用户名
- 用户名
- 用户级
- 用户登录
- 用户名
- 用户通行证
- 用户注册
- 用户状态
- 用户地址
- 嗯
$author\u id
变量之前使用global$post
,才能工作。如果你想检索author元数据而不回显它立即,使用get_the_author_meta(字段,id);get_avatar_url($author_id)是获取作者头像url的更好方法。这对我很有用,谢谢兄弟:)