Using Author Template Tags Outside of the WordPress Loop

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:

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:

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:

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.

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.

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.

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

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.

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?

[…] 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. […]

[…] – 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 […]