WordPress:从帖子ID获取作者信息

问题描述 投票:41回答:2

甚至是帖子id的作者身份证明。我试图在单个帖子页面(在post循环之外)的侧边栏中返回作者meta(作者页面链接和头像)。做这个的最好方式是什么?我正在使用自定义函数(见下文)来返回帖子ID,但我不确定接下来要调用哪个函数。

function this_post_id() {
  global $wp_query;
  $thePostID = $wp_query->post->ID;
  return $thePostID;
}
php wordpress
2个回答
68
投票

我想到了。

<?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 ); ?> 

18
投票

如果你想要它在循环之外,那么使用下面的代码。

<?php
$author_id = get_post_field ('post_author', $cause_id);
$display_name = get_the_author_meta( 'display_name' , $author_id ); 
echo $display_name;
?>
© www.soinside.com 2019 - 2024. All rights reserved.