Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm looking for a way to create a parent authors page and then use the author.php for the individual author pages. I've been out of the loop (no pun) for a couple months and am wondering the best way to do it.

share|improve this question
    
What do you need in this "parent" page? why not use regular page? –  Bainternet Feb 26 '12 at 21:07
1  
I'd like to create a page of authors and have them link to individual author's pages. –  hoss9009 Feb 28 '12 at 4:49
add comment

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
1  
Thank you. As for my comments, those were in response to kaiser's comments on my supposed laziness. I hope they do create noise... if there are "volunteers" then I would hope that they would realize that they don't HAVE to help. Me expressing my sadness for him not helping me understand the difference between PHP and the WP Codex and his smug ideals that we should ALL know EVERYTHING,doesn't help anyone. BC I thought this was a WP issue, I posted it in WPSE. Now that someone has actually explained this to me, I can move on. –  hoss9009 Feb 29 '12 at 5:24
1  
The core of your question is a WP issue, so this was definitely the right place for it. Just a disconnect over terminology. Glad you've got everything sorted out. :-) –  EAMann Feb 29 '12 at 5:26
    
@hoss9009 Just for the record: »This Q does not show any research effort;« is what you read when you hover over the down vote arrow for a Q. No one expects that you know everything. But we expect you to do research on equal height to the difficulty of your Q. If you're asking something, get an answer that fits and then are not able to implement it, then you asked something above your research effort. The only reason for all the patience here is that we a) want to keep the system friendly and b) let it become the ressource and b) you're new. So, please keep this in mind for further Qs. –  kaiser Feb 29 '12 at 12:23
    
Wow @kaiser, I'm glad you know exactly what I've done to solve this problem. Assuming doesn't help me... at all. I have researched my issue and have found two, just TWO articles with information on them: 1 & 2 Obviously, Justin Tadlock was a little helpful, but doesn't help w/ avatars exactly how I would like. The WPSplash ex is a lil' weak. I could assume you lack brain function, but I won't because that would be rude, so I won't. –  hoss9009 Mar 1 '12 at 13:50
    
@EAMann thank you for your support and only commenting to help and be productive, unlike others. –  hoss9009 Mar 1 '12 at 13:51
add comment

Use internal/built-in classes

WP got …

Example code

$authors = new WP_User_Query( array(
     'role' => 'editor',
     'fields' => array(
          'first_name',
          'last_name'
     )
) );

Then just loop through your results (the authors) in a custom template file and assign this to a normal page.

<?php
/*
Template Name: Editors Page
*/

// Query goes here

foreach ( $authors as $author )
{
    // Inspect the author data
    var_dump( $author );

    // EXAMPLE: display author first & last name
    echo "{$author->first_name} {$author->last_name}";

    // Link to author posts @see        http://codex.wordpress.org/Function_Reference/get_author_posts_url
    get_author_posts_url( $author->ID );
}
share|improve this answer
    
Kaiser... thanks. But I'm not sure exactly how to use this... sorry im kind of a dummy when it comes to the loop. How do I create a loop based off of this info. Basically, I want to treat the author.php template as a profile page. –  hoss9009 Feb 28 '12 at 4:36
    
And I'd like to create a page that displays all the users. –  hoss9009 Feb 28 '12 at 4:40
    
See Update. Basically, I can just tell you to spend some hours on php.net and similar and learn basic php. This will avoid such Qs and help you searching and implementing much easier, which is over all a time saver for you. –  kaiser Feb 28 '12 at 8:29
    
No helps for newbs? Sad... –  hoss9009 Feb 28 '12 at 14:27
1  
there is everything you need here codex.wordpress.org/Class_Reference/WP_User_Query –  Bainternet Feb 28 '12 at 18:23
show 17 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.