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.
If you want to create a custom author page in WordPress, start with the WordPress Codex article on WordPress Custom Author Template Files, good advice on how to create a custom author template file.
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.
I found the solution in the WordPress Custom Author Template Files article on the WordPress Codex.
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()) : ?>
<?php
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin(get_the_author_login());
else :
$curauth = get_userdata(intval($author));
endif;
?>
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>
<div id="authorinfo">
<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>
</div>
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(); ?>
<div class="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.
Related Articles
- 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
Subscribe
Via Feedburner
Subscribe by Email
Copyright Lorelle VanFossen, the author of Blogging Tips, What Bloggers Won't Tell You About Blogging.
29 Comments
Thanks for the step-by-step explanation. I’m thinking that the concept here could be applied to create other specialized pages by switching out the tags.–Dan
Nice article, thanks.
Those of us who would rather not tinker with PHP will wait for a plugin or widget.
Kafkaesquí’s Get Author Profile Plugin
I want to show up the authors with no posts (yet). Can u help ?
Empty Authors and Categories will not appear by default on a WordPress blog. If you need to know the number of posts for specific authors within your Administration Panels, check out one of the different statistics in Counting WordPress: Statistics WordPress Plugins for author statistics.
Other than that, the best place to look for a custom script or request one would be in the WordPress Support Forum.
Do you know how to get the Userextra and/or Usermeta plugins to work for the author.php page.
I’ll filles in the adres value and want to print Extended User Data which is profided using the plugin:
If you want the Plugins to work in the author.php, you have to put the Plugin template tags into the template file, author.php. Follow the instructions EXACTLY as put in the readme.txt or on the Plugin author’s website and that will allow you to add the meta information.
If you need more help with the Plugins, please contact the Plugin author directly.
thanks so much for this, it REALLY helped me out a lot on my author pages!
Great Article! But how do I get the author image onto the author page?
There are WordPress Plugins to create variables which include photographs of the authors onto the author.php template file. See WordPress Plugins for Multiple Blogger Blogs for examples.
I had the same problem actually. I used the Loop to display ONLY author information (no posts), but it would duplicate. If the author had posted 3 posts, the author information would be displayed 3 times. I had to get the information out of the Loop. Thanks for the tips.
Need to connect to a Database outside of wordpress.
Is this possible and if possible how do one do it.
So where is an example of this in action … when I click on any link that goes to your author page, all I see is a list of your posts, not your custom stuff …
@ @Babiesonline:
I can’t do things like this on my WordPress.com blog. You can see this at Taking Your Camera on the Road, though it is currently in flux so pardon my dust if things aren’t working quite right. 😀
I also have examples of this in my genealogy blog.
Have you ever been able to add a picture of the author? How about other fields like hobbies, more than one site, links to other sites they want to showcase?
@ Jamie Birch:
Adding a picture to the author page and elsewhere is easy. Check out the article details and links within and these WordPress Plugins: WordPress Plugins for Multiple Blogger Blogs.
Great post Lorelle! I’m building a custom author.php for my WordPress blog using snippets from your post and I’m having troubles with listing an author’s posts! The tag the_permalink() is throwing up strange outputs! Have a look at them at http://test.potenz.co.in/author/admin
Any idea if you can test, within the `user_url; ?>` statement, for the presence of a URL on the user record, and if one does not exist suppress the display of the default “http://”?
Thanks!
H
Hedley,
you can do something like this:
user_url) {
echo $curauth->user_url
} else {
// Do nothing
}
?>
Nice trick, Lorelle!
Well, that didn’t work… Lets try it without the php tags…
if (!empty($curauth->user_url)) { echo $curauth->user_url; } else { }
Hi there! nice post, very useful!
I have an uncommon request.. I’d need to list authors depending on the period they wrote..
for istance I have authors that wrote only on march 2008 and never again.. how could I list them?
thanks!
Andrea
Your request is actually quite common, and the answer is “it depends.” It depends upon how you highlight authors, what your agreement and arrangements for allowing the contributors to work on your site, and how valuable it is to you to highlight their names. If they are top notch, recognizable names, then no one cares when they wrote the content, it’s the names that matter, so leave them in the list.
If you did not specify any agreement for inclusion on the list, then take them out by finding a Plugin (or writing one) that works with the wp_list_authors template tag to exclude author IDs. Not familiar with one, but you might be able to find such a Plugin. Or create a manual author list that links to the author pages of posts.
To list authors by time period of their contribution, then create a manual list with the names and dates in the link.
Otherwise, how important is it to highlight the authors in a list? Why not let their bylines link to their author pages and skip the list. Those seeking posts only by a specific author will click on the author byline link to find all the posts they’ve written.
yeah..you said mostly right..
but in this particular case I will have on my blog 7 writer that will change each month..so u may imagine that I might need to classify them depending on the period they wrote..anyway I’ll figure it out..
I guess should be something dealing with a particula while-have-post condition that satisfy the dates I need and then show just author link instead that post excertp or other post stuff.
thank u anyway 😉
Andrea
No, there isn’t a conditional script I can think of that would check dates and such. Do check the WordPress Support Forums for more help. I’m sure someone might have a better suggestion.
I still recommend that you skip the list of authors and simply have every byline link to the author.php template file to display posts by that author. The byline credit is usually more important than being on a list for a month or less. Are you sure your readers care “when” someone wrote something or care more about what they wrote not who wrote it?
This post has helped me out so many times, Thanks for writing it! 🙂
Lorelle: Thank You!
I tried and tried to pull the_author_meta and it finally dawned on me that I was outside the loop. Durrr. So, thanks for another very helpful post here, saved me a lot of additional frustration.
GREAT post! Thanks for this information, it was just what I needed for another couple of sites I’m working on. Really appreciate that you put it out there for all to see!
Thank you Thank you Thank you
I had the same issue. Display some author’s data OUTSIDE the loop.
Regards
Juergen
15 Trackbacks/Pingbacks
[…] https://lorelle.wordpress.com/2006/05/06/using-author-template-tags-outside-of-the-wordpress-loop/ […]
[…] I love challenges and recently I was challenged with a way to make information about a post author show up in a WordPress Theme outside of the WordPress Loop, which I explained in “Using Author Template Tags Outside of the WordPress Loop”. Another even challenging author issue came up with my genealogy blog. How to add dead authors to my blog authors and users. I uncovered the mysteries in “Blog Contributors – Wanted Dead or Alive”, and had some morbid fun while I was at it. In the future, I will use this information to create more customized author pages, so stay tuned for more on this. […]
[…] Using Author Template Tags Outside of the WordPress Loop by Lorelle […]
[…] Lorelle on wordpress […]
[…] Using Author Template Tags Outside of the WordPress Loop […]
[…] Using Author Template Tags Outside of the WordPress Loop […]
[…] Using Author Template Tags Outside of the WordPress Loop […]
[…] – I finally managed to get my head around using WordPress template tags outside The Loop (thanks to this blog post), meaning that I could get a nice, personalised page for each author’s archive. Other neato […]
[…] Using Author Template Tags Outside of the WordPress Loop […]
[…] Using Author Template Tags Outside of the WordPress Loop « Lorelle on WordPress […]
[…] Using Author Template Tags Outside of the WordPress Loop […]
[…] Using Author Template Tags Outside of the WordPress Loop […]
[…] Using Author Template Tags Outside of the WordPress Loop […]
[…] Using Author Template Tags Outside of the WordPress Loop […]
[…] Using Author Template Tags Outside of the WordPress Loop […]