0

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(); ?>
    <?php
                    }
                    else {
                        ?>
                        <?php if( get_the_category_list() ) { ?><p class="alignleft"><span><?php the_category( ', ' ) ?></span></p><?php } ?>
            endwhile;
        endif;
10
  • @rajeshrt - What does "I am facing pro in category..." mean? Commented Feb 2, 2011 at 6:49
  • i mean "i am not getting right solution using the above code"
    – rajeshrt
    Commented Feb 2, 2011 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
    Commented Feb 2, 2011 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
    Commented Feb 2, 2011 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
    Commented Feb 2, 2011 at 8:52

1 Answer 1

0

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

change the

&paged='.$paged

to

&offset='.$paged

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.