Since this blog has two authors, we thought it might be nice to have an easy way for people to see which posts Paul wrote and which ones I wrote.
WordPress makes all of this pretty easy but you have to know where to look. The best resource is the WordPress Codex page for the Author Templates.
I thought some real world code examples might be useful, so here are the changes that I made to our template to get the author links to show up under the title of the posts and in the sidebar.
Link to author’s posts under the post title
I started with the while loop of the index.php file. We are using the Copyblogger theme as our base template so this is what it looks like now. The code to add the authors is in bold.
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<p>Post written by: <?php the_author_posts_link(); ?></p>
<p class=”post_date”><?php the_time(’F jS, Y’) ?> — <?php the_category(’, ‘) ?></p>
<div class=”entry”>
<?php the_content(”Continue reading →”); ?>
</div>
<p class=”post_meta”><span class=”add_comment”><?php comments_popup_link(’No Comments’, ‘1 Comment’, ‘% Comments’); ?></span></p>
<?php endwhile; ?>
The code above adds the author’s name and a link to all of their posts below the title and before the date and category line. I did almost exactly the same thing in the archive.php and single.php files.
Add links to each author’s posts in the sidebar
<li class="widget">
<h2>Authors:</h2>
<ul>
<?php wp_list_authors(); ?>
</ul>
</li>
The important part is in bold. The rest just blends it in as its own section in the sidebar so you should modify that to match the way your own template handles the individual blocks in the sidebar.
What happens when you click on one of the authors?
When you click on the Mike or Paul links, WordPress looks for an author.php file. If it finds one, it uses that to display the page. If not, it uses the archive.php. If there is no archive.php, it uses the index.php. No matter what, it will only display the posts of the author you selected.

0 comments ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment