WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to display one post from each category per page. So the first page would contain the first post of cat A, the first post of cat B and the first post of cat C. The second page would contain the second post of cat A, the second post of cat B and the second post of cat C.

I currently use the following code, but it does not work, I always get the same posts.

$category_ids = get_all_category_ids();
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

foreach($category_ids as $kk=> $cat_id) {
    $cat_name= query_posts( 'cat='.$cat_id.'&posts_per_page=1&orderby=date&order=ASC&paged='.$paged);
    foreach($cat_name as $post) : setup_postdata($post);
        if (have_posts ()) :
            while (have_posts ()) : the_post(); ?>
                    else {
                        <?php if( get_the_category_list() ) { ?><p class="alignleft"><span><?php the_category( ', ' ) ?></span></p><?php } ?>
share|improve this question
@rajeshrt - What does "I am facing pro in category..." mean? – MikeSchinkel Feb 2 '11 at 6:49
i mean "i am not getting right solution using the above code" – rajeshrt Feb 2 '11 at 6:51
@rajeshrt: Could you edit your question to add a description of what you are trying to do here? I don't get it by reading your code. Maybe include an example of how the result should look? (When you are done, add a new comment and use @Jan in it, so I get a notification.) – Jan Fabry Feb 2 '11 at 8:28
@jan yaa i want to say that i want the latest post per category that will display on home page and the remaining will be displayed on page/2,page/3 ect. i know their is plugin available but i dont want to use that i want the specific code that will give me that result. – rajeshrt Feb 2 '11 at 8:41
@rajeshrt: What is the name of that plugin? You can look at the code and learn from it to build your own solution. You must keep in mind the built-in paging system, otherwise WordPress won't load your template. – Jan Fabry Feb 2 '11 at 8:52
up vote 0 down vote accepted

If you are only showing one post of each category then in your query_posts()

change the



share|improve this answer

Your Answer


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.