0

I have 3 authors, each of us talk about the same subject but in a different mind/opinion. I want to have 3 pages for each of us and show ONLY the posts for each author one them.

Like have a page called AuthorOne that has only the first authors posts, etc. How can I do this?

1
  • Why don’t you use the author archive?
    – fuxia
    Mar 4, 2013 at 22:16

2 Answers 2

1

When you look at the Template hierarchy, then you'll notice that there're actual author archives:

Archive Page: author-{$nicename}.php >> author-{$id}.php >> author.php

This means, that you can simply add an author.php file to your theme and style it whatever you want. The Loop will give you all posts by this author. If you want to style them differently per author, then use author-{$nicename}.php template files.

enter image description here

0

I think, query_posts('author=' ID OF THE DESIRED AUTHOR) is what you are looking for.

An example:

query_posts('author=' ID OF THE DESIRED AUTHOR);
while ( have_posts() ) :
    the_post();
    DO YOUR STUFF
endwhile;
wp_reset_query();

// Edit

You can, of course, incorporate a certain category or some other filter argument into your query.

Link to the Codex for query_posts.

10
  • Please don't use query_posts(). It's a bad advice, as it overwrites the main query object.
    – kaiser
    Mar 4, 2013 at 22:41
  • @kaiser - Hm, it's a bad advice doesn't read that nice, in my opinion. Of course, using the author archive is a good (most probably even 'better') way. However, the question was about THE listing of posts on THE page, so I thought it legitimate to assume it would be THE (main) query. And if not, I included the link to the codex (for caveats and drawbacks etc.) and I also included wp_reset_query in my example.
    – tfrommen
    Mar 4, 2013 at 22:55
  • @kaiser I agree with @t f. I want to have 3 *pages* for each of us There is no 'main query' on a page. If you want to display e.g. post from a single category, then yo have to use wp_query
    – Ralf912
    Mar 4, 2013 at 23:05
  • 1
    @tf query_posts should never be used, period. if it's a modification of the main query, use pre_get_posts, if it's an additional query (as in your example), use WP_Query.
    – Milo
    Mar 4, 2013 at 23:15
  • 1
    @Ralf912 - you are mistaken. there is a main query on every page/post type, including page. when you load posts via query_posts on a page, you overwrite the page's query. the is_page() conditional will return false when it should be true. if you have code which relies on knowing the context of the main query, it will produce unexpected results. there is no reason to ever use query_posts, WP_Query will achieve the same results without overwriting the main query.
    – Milo
    Mar 4, 2013 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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