2010-07-06 118 views
33

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

function this_post_id() { 
    global $wp_query; 
    $thePostID = $wp_query->post->ID; 
    return $thePostID; 
} 

回答

58

我想通了。

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

很酷 - 我会删除我的答案,因为它是误导。很高兴你对它进行了排序 – 2010-07-06 19:01:56

+7

为了记录,使用echo the_author_meta是多余的,因为the_author_meta已经回应了原来的值。 – 2012-05-14 01:09:14

+4

注意:您必须在'$ author_id' var之前使用'global $ post'才能正常工作。 – BandonRandon 2012-12-27 20:03:15

1

如果你想在循环之外使用下面的代码。

<?php 
$author_id = get_post_field ('post_author', $cause_id); 
$display_name = get_the_author_meta('display_name' , $author_id); 
echo $display_name; 
?>