WordPress allows you to create a custom Author web page for your WordPress blog. You can make this page look like anything you want, customized to the author or with just some tidbits about the author added to the page to help readers learn a little more about the person behind the post.
I had very specific ideas about the look and what information I wanted on the author page for my new WordPress blog. Since I am planning on working with a variety of authors, I wanted to showcase each author’s contact information, home website, a description or bio of the author, and then a highlighted list of the articles the author has published on the blog. This turned into a bit more of a project than I planned, so I thought I would share my techniques with you.
Typically, most WordPress blogs have only one author, therefore, most WordPress Themes, if they include a byline or author information, do so as plain text. WordPress has a template tag that can replace the standard author template tag to turn the author’s name into a link. Click the link and the visitor is taken to a web page that generates a “search result” listing of posts by that author. Very simple and automatic.
To create such an author link, Change the commonly used
<?php the_author(); ?> template tag to:
<?php the_author_posts_link('namefl'); ?>
A link with the name of the author will be automatically generated, such as:
You can add this template tag author link as a byline or in the post meta data section of your posts. When clicked, the link will go to the
index.php template file to generate a list of posts written by that author, or, if you have it, use the
author.php template file which you can customize to make it look however you want. I had very specific ideas on how I wanted my custom author template page to look.
Because I don’t do simple things like rely upon WordPress to just generate the author’s page by default, I wanted to create a customized author page with contact information and a biography for each author. I created a customized
author.php template file which WordPress seeks automatically when an “author link” is clicked.
Remember, when working with default template hierarchy files, you don’t need to do anything. WordPress will search through a set of template files and if it finds it, it will automatically use it. If it doesn’t, it goes back to the default, which is the
index.php template file. So, if it is there, it uses it. For more on how template files work in WordPress, see Stepping Into Templates.
On my custom
author.php template file, I wanted the title to read Articles by Lorelle VanFossen, or whoever the author is. I also want a short list of the author’s main website, email contact, and biography, helping readers learn more about the author. Then the WordPress Loop would begin, generating a list of posts by that author.
The template tags and text I wanted to use should have looked like this:
Articles by <?php the_author(); ?>
Author Website: <?php the_author_url(); ?>
Author Email: <?php the_author_email(); ?>
Author Bio: <?php the_author_description(); ?>
However, I have a little problem.
The template tags I wanted to use work only within the WordPress Loop, a bit of PHP code that gathers information from the database and displays it. By using these template tags outside of the Loop, the key that starts the process of gathering information from the database isn’t initiated, so there is nothing to find. They don’t work.
If I used these template tags within the WordPress Loop, so they will work, this information would be generated on each and every post returned written by the author. That’s too much duplicate information. I wanted to list this information separately from the post search results, and to only display once. Yet, these tags only work inside the Loop. I had to find another method of calling the information from the database outside of the WordPress Loop.
It begins by adding a GET call to the database (to GET data) placed just below the call to the header in the
author.php template file. It creates a kind of mini-loop, gathering information about the author from the database and assigning it to variables which can then be used outside of the WordPress Loop:
<?php get_header(); ?>
<?php if (have_posts()) : ?>
$curauth = get_userdatabylogin(get_the_author_login());
$curauth = get_userdata(intval($author));
In the area where I want the information about the author gathered from the database to display, I added the following, totally replacing the Loop template tags I wanted above:
<h2 class="posttitle">Articles by <?php echo $curauth->display_name; ?></h2>
<p><strong>Author Website:</strong> <a href="<?php $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a><br />
<strong>Author Email:</strong> <a href="mailto:<?php echo antispambot($curauth->user_email); ?>">Contact Author</a><br />
<strong>Author Bio:</strong> <?php echo $curauth->description; ?></p>
Note that I changed the way the Author Contact information and tag is laid out. I took advantage of a WordPress built-in feature that hides the email address from bots and harvesters that steal email addresses for spam. If I was using the email tag within the Loop, it would be
<a href="mailto:<?php echo antispambot(get_the_author_email()); ?>">Email Author</a>. Just for your information.
From there, the Author Template File goes on as usual, and the WordPress Loop begins, gathering information about the posts written by the author. It is not necessary to change the following in your
author.php template file. This is just an example of how I laid out my author search results:
<?php while (have_posts()) : the_post(); ?>
<h2 id="post-<?php the_ID(); ?>" class="posttitle"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div id="searchinfo">By: <?php the_author_posts_link('namefl'); ?> | Categories: <?php the_category(', '); ?> | Comments: <a href="<?php the_permalink() ?>#comments" title="<?php the_title(); ?>" rel="bookmark"><?php comments_number('0','1','%','%'); ?></a></div><!-- end searchinfo -->
<div class="entry"><?php the_excerpt(); ?> <div class="readmore"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">CONTINUE READING</a></div>
</div><!-- end of entry -->...
The end results of my custom
author.php template file for the section with the author details looks like this.
Thanks to the great folks who volunteer their amazing talents on the WordPress Codex for helping me figure this out!
For more WordPress Plugins and techniques for customizing author pages and the author template file, see WordPress Plugins for Multiple Blogger Blogs.
- Customizing Your WordPress Theme Footer
- WordPress Tip: How to Display a Specific Post Anywhere You Want
- Showing Dates Not Just Times in Your Multi-Post Views
- Post Meta Data WordPress Plugins
- WordPress 2.1: Template Tag and Function Changes
- Abhijit Nadgouda’s List of WordPress Global Variables
- Cybercafe Experiments: How to Convert Any Web Template Into a WordPress Theme
- Creating Effective, Attention-Getting Headlines and Titles
- When the Blog Breaks: Fixing Your Broken Blog
- Display Post Excerpts Only in WordPress
- Tags and Tagging in WordPress
- Dissecting the WordPress Post Title Link
- Editing the Edit This WordPress Template Tag
- Problem Solving the WordPress Header
- WordPress Tips and Tricks for Template Files
- WordPress Template Files and Style Sheets – Give Them a Name
- What I Needed to Learn About WordPress
Site Search Tags: wordpress tips, wordpress themes, author page, author template file, author template, author template tags, custom author pages, multiple bloggers, multiple authors, customizing author pages