Question

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;
Was it helpful?

Solution

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

change the

&paged='.$paged

to

&offset='.$paged
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top