2017-01-01 38 views
0

我想在我最近的博客文章中顯示作者的名字。我嘗試過,但沒有工作。有人請幫助我。在最近的博文中得到作者姓名

$args = array('numberposts' => '8'); 
    $recent_posts = wp_get_recent_posts($args); 
    foreach($recent_posts as $recent){?> 
     <i><?php echo get_the_author(); ?></i> 
     <i><?php echo $recent['post_author']; ?></i> 
}?> 

get_the_author();它沒有顯示任何輸出。而 $recent['post_author'];它表明所以輸出1

回答

0

get_the_author()不會在環路後外出打工是不適合用在wp_get_recent_posts()使用。

您的第二個版本$recent['post_author']正在輸出正確的值。你看到1,因爲它是作者的ID而不是他們的名字。你需要拿到身份證並用它來檢索他們的名字。

使用the_author_meta()輸出的顯示名稱值:

<?php the_author_meta('display_name', $recent['post_author']); ?> 
+0

非常感謝你的答案... – tstudent