Getting the author name on author archive page inside WordPress

I am making template for archives in WordPress website, but my template will not work for author name on author archive.

I have this:

Read More
<?php if (is_category('')) { ?>
<?php single_cat_title(); ?>

<?php } elseif (is_author('')) { ?>
<?php get_userdata( get_query_var('author') );?>

<?php } elseif (is_day('')) { ?>
<?php echo get_the_time('F j, Y'); ?>

<?php } elseif (is_month('')) { ?>
<?php echo get_the_time('F Y'); ?>

<?php } elseif (is_year('')) { ?>
<?php echo get_the_time('Y'); ?>

<?php } elseif (is_tag('')) { ?>
<?php echo single_tag_title(''); ?>
<?php } ?>

This part will not work:

<?php } elseif (is_author('')) { ?>
<?php get_userdata( get_query_var('author') );?>

Related posts

Leave a Reply

2 comments

  1. WordPress supports an archive template for that. You simply have to add an author.php file to your theme folder: http://codex.wordpress.org/Author_Templates

    And than you can use all author functions like:

    • get_the_author() for the author name
    • get_the_author_meta('description') for the description
    • get_avatar( get_the_author_meta('ID'), 40 ) for the avatar

    There are also archives for categories (http://codex.wordpress.org/Category_Templates) and Tags (http://codex.wordpress.org/Tag_Templates) btw.

  2. The function you’re using in is_author returns a user object. It doesn’t output anything.

    Correct usage would be:

    <?php 
    // Get current author.
    $curauth = ( get_query_var( 'author_name' ) ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) ); ?>
    
    Author: <?php echo $curauth->nickname; ?>
    

    Also the empty string isn’t necessary with is_category etc.