First, Explaining Loops
You’re dealing with two kinds of “loops.” The first is a loop in PHP, the second is a loop in WordPress.
Loop in PHP
kaiser gave you some code that will generate a list of authors on your site. You can iterate through this list and print information on the screen.
// Fetch an array of authors from WordPress and store it in the $authors variable
$authors = new WP_User_Query( array(
'role' => 'editor',
'fields' => array(
'first_name',
'last_name'
)
) );
// For each author in $authors, we display their name and a link to their author archive page
foreach ( $authors as $author ) {
// EXAMPLE: display author first & last name
echo "{$author->first_name} {$author->last_name}";
echo get_author_posts_url( $author->ID );
}
If you have two members on your site in the “editor” role, the WP_User_Query()
call will return a PHP array with two objects in it, each object representing an author. You loop through that array and write out the information from each object in turn.
The WordPress Loop
WordPress calls its standard post system “The Loop.” It’s a standard set of code that’s used in each page template, index template, archive template, etc to display post content. The standard Loop looks something like this:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
// Code for individual posts goes here
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Inside the Loop (the // Code for individual posts goes here
part) you can use special functions like the_title()
, the_permalink()
, the_content()
, etc.
What You Need
You need two pages in your theme. First, you need an author.php
, as you already indicated in your question. This will display an archive of each post written by a specific author. For example, http://yoursite.url/author/john-doe
will list all posts written by an author with the slug, “john-doe.”
You also need to create a custom page template. I would recommend something called author-parent.php
or something along those lines. This template file should use WP_User_Query()
to fetch a list of users, display those user names, and display links to individual user archive pages.
Then, you need to create a page in WordPress and assign this custom template to that page. When you visit that page in the browser, WordPress will load your custom template and print out the data you’re looking for.
Now, a Word on Rules
The WordPress Answers Stack Exchange is a question and answer site. You need to ask clear, specific questions with as much detail as possible. If people ask you clarifying questions in comments, those are intended to help you refine, clarify, and further flesh out your question.
Don’t just continue to leave comments. Go back and edit your original question to add extra information. If we can’t figure out what you’re asking, we can’t answer your question.
When any question or answer accumulates more than 20 comments in a short period of time, it is automatically flagged by the system for moderator attention. That many comments means something is wrong.
Comments like:
No helps for newbs? Sad…
And:
Sad… I thought I would actually get some help here…
Do nothing to clarify or contribute to the conversation. They’re off topic, create noise, and make it more difficult for the volunteers on the site to help you.
Please take a moment to review the FAQs for the site. They outline how to ask questions on the site and participate in the community. I have no doubt that you can find answers to your questions here. Just remember, if we’re responding to your questions with “I don’t understand” or if there are long comment strings like above, then you might need to rephrase your question. Or just give an example of what you’re trying to accomplish; even if you don’t know the right technical terms for what you’re doing, explaining it in plain enough language will often be enough.