I am making template for archives in WordPress website, but my template will not work for author name on author archive.
I have this:
<?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') );?>
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_TemplatesAnd than you can use all author functions like:
get_the_author()
for the author nameget_the_author_meta('description')
for the descriptionget_avatar( get_the_author_meta('ID'), 40 )
for the avatarThere are also archives for categories (http://codex.wordpress.org/Category_Templates) and Tags (http://codex.wordpress.org/Tag_Templates) btw.
The function you’re using in is_author returns a user object. It doesn’t output anything.
Correct usage would be:
Also the empty string isn’t necessary with is_category etc.