WordPress:从帖子ID获取作者信息 [英] WordPress: get author info from post id
本文介绍了WordPress:从帖子ID获取作者信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
甚至是帖子ID中的作者ID.我试图在单个帖子页面(帖子循环之外)的边栏中返回作者元数据(作者页面链接和头像).做这个的最好方式是什么?我正在使用自定义函数(请参见下文)返回帖子ID,但不确定接下来要调用哪个函数.
Or even the author id from the post id. I am trying to return the author meta (author page link and avatar) in the sidebar of a single post page (outside of the post loop). What is the best way to do this? I am using a custom function (see below) to return the post id, but am not sure what function to call next.
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 ); ?>
这篇关于WordPress:从帖子ID获取作者信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文