Authors Loop with Links to Pages – WordPress Tutorial

Authors Loop WordPress

Much like this roller coaster, a good WordPress Loop should be versatile, even for Authors

Creating the loop for a page that displays all of your authors in your WordPress website is something that’s not as straight-forward as you would think it would be. Additionally, actually linking to the author’s page is fairly tricky. So today I am going to show you how to do it. You can take the final code and put it in a page called page-pagename.php in your template folder, replacing “pagename” with the name you want to page to have. For more info on that, view the WordPress codex page about page templates.

So let’s get down to it. I’ll just post the full PHP code here and then explain some of it after.

PHP author loop code that links to each author page

In the first section we are really just setting up our variables and beginning the query. You can define $args for any arguments you want applied to your query. Currently I’m just using ‘who’ => ‘authors’ to specify that we only want authors, not other users. For a more complete list of options for the query, check out the WordPress page on the WP User Query.

Then we actually have a foreach loop, which goes through each author and displays them along with a link to their page, some information, their avatar, and 30 words of their description in this case. If you need any help customizing this, let me know.

Creating the link to the Author Page

I would argue this is maybe the trickiest part to figure out. There is little documentation on this and you would THINK that there would be an obvious built-in function to do it. There IS a function that will list all the authors and link to their pages, wp_list_authors, but it isn’t very customizable and not nearly versatile enough for a full author-results template page. But when I took a look at the code behind wp_list_authors, I found get_author_posts_url which seems to get the job done.

That should really be all you need! Other than that, this pretty much works like any other loop. You can add any custom HTML, formatting, or author author information in the foreach loop to customize as needed. Using this, you can create a fairly robust author results page similar to any post results page.

About Brian Johnson

Brian Johnson is a website developer and designer living in Minneapolis, Minnesota with a passion for code and WordPress. He spends his days building WordPress websites for small businesses, developing new code with the online community, and living life.