I created an author’s page using:
<?php
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin($author_name);
else :
$curauth = get_userdata(intval($author));
endif;
?>
and then a standard loop, which displays all posts’ titles published by that author. I’m trying to separate the display of the posts, according to the category they belong to (1, 2 or 3), so I tried using
<?php query_posts('cat=1'); ?>
but then all my blog posts are displayed, not just that author’s. Something is certainly wrong.
I know I have to use a custom query when there is more than one loop per post, but given that just using a single standard query, with the “cat” filter isn’t working, I’m a bit lost.
If you’re using an author template there’s absolutely no need to setup(set) the author query parameters, they’ll be setup ready in the query object present on the author page..
You could additionally avoid the need to create numerous queries(one per category currently), by iterating over the query you have, extracting the categories, and storing post IDs associated with given categories inside an array. First iteration you use to build the array of IDs divided by category name/ID(whatever you like), then rewind the query, iterate over the posts, continuing(skipping) results that don’t match the first category in your newly built array of category IDs(or names). Again you follow by rewinding the loop, then iterating over it again for each category you have in the new array, continuing(skipping) posts when they don’t match the current category iteration.
It’s not something that will really make much sense until you see it, and gets a little more complex if you categorize your posts into multiple categories(where the categories can intersect across posts), but it will work(without any additional queries) for the current page(it obviously won’t sort the full result set, so whilst a given page will sort, that overall sort won’t carry across the sum of all pages for the result set).
If you think the above method sounds useful and you’re not fussed about the aforementioned problem i don’t mind providing an example.
Solved in a much much much simpler way
I have one loop per each category I need to display, and the query is built using: