WordPress.org

Ready to get started?Download WordPress

Forums

Author Archive: show the name of the author (3 posts)

  1. johndporter
    Member
    Posted 6 years ago #

    I wanted to be able to show the name of the author when viewing an "Author Archive". The default listing header just says
    Author Archive

    To include the name of author, I first tried simply inserting code as follows:

    Author Archive for <?php the_author() ?>

    However, this does not work. The "hack" to set $post from $posts[0] at the top of archive.php doesn't work, because the_author does not get its info from $post, but rather from $authordata. Therefore, to make this work, I simply added the following line after $post = $posts[0]:

    $authordata = get_userdata($post->post_author);

    Presto.

  2. Georgi
    Member
    Posted 6 years ago #

    johndporter, thanks for sharing that. By me it was not enough to show author's name. But after adding the line(as you advised)

    $authordata = get_userdata($post->post_author);

    instead using
    Author Archive for <?php the_author() ?>
    I use
    Author Archive for <?php echo $authordata->user_nicename; ?>

    Then it was ok.

    Cheers.

  3. Zoinks! Graphics
    Member
    Posted 6 years ago #

    Sweet! This is just what I was looking for. Thank you both!

Topic Closed

This topic has been closed to new replies.

About this Topic