Display Multiple Authors In WordPress

Posted In CMS, Tips, Web Development, Wordpress - By technologystory On Saturday, June 27th, 2009 With 0 Comments

Ever needed or wanted to know how to display more than one author’s posts on a WordPress blog such as the homepage? Thanks to the many functions within WordPress this is quite easy to do and requires only a few lines of code.

In order to show more than one author we are going to use the query_posts() function. In order for this to work correctly you need to place the code before the beginning of the code that starts The Loop. An example query_posts() fucntion would look something like the following.


In the above code you can see the variables that we set inside of the parenthesis and within single quotes; author_name and showposts. The author_name variable is the username for the author that you are wanting to display, not the first or last name (the username can be different from the display name). The showposts variable just sets how many posts you would like to have displayed. Pretty simple right? The only thing left now is to add in the code used to check if there are posts, the code to display the post’s information and then close the loop itself.

Code to display the post goes here

The above code will allow you to use multiple loops on your WordPress blog in order to display as many author’s posts as you would like. All that you have to do is change the author_name variable to whatever author you would like to show.

Lets go ahead and write out a sample piece of code that would list 2 different authors.

There you have it, the above code will display the latest 5 posts from the author with the username of admin and then display the latest 5 posts from the author with the username of bobo. You can use IDs for each author’s posts in order to give each author’s content their own custom look.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>