Support » Themes and Templates » multiples loops in interlayered categories without duplicates

  • I need to make a homepage with a layout like this:

    • last post from category1
    • last post from category2
    • last post from category3
    • another post from category1
    • another post from category2
    • another post from category3

    The examples in The_Loop works using $do_not_duplicate = $post->ID; in category1, but the other 2 categories get duplicated posts.

    None of the examples I found online works with interlayered categories, any ideas???

Viewing 2 replies - 1 through 2 (of 2 total)
  • Here’s my code, what am I doing wrong???

    <?php $do_not_duplicate = array();
    query_posts('category_name=category1&posts_per_page=1');
    while ( have_posts() ) : the_post();
    $do_not_duplicate = $post->ID; ?>
    <!--Do Stuff-->
    <?php endwhile; ?>
    
    <?php $do_not_duplicate = array();
    query_posts('category_name=category2&posts_per_page=1');
    while ( have_posts() ) : the_post();
    $do_not_duplicate[] = $post->ID; ?>
    <!--Do Stuff-->
    <?php endwhile; ?>
    
    <article class="post" id="postmedium">
    <?php query_posts( array(
        'category_name' => 'category1',
    	'posts_per_page' => 1,
        'post__not_in' => $do_not_duplicate
        )
    );
    while ( have_posts() ) : the_post();?>
    <!--Do Stuff-->
    <?php endwhile; ?>
    
    <?php query_posts( array(
        'category_name' => 'category2',
    	'posts_per_page' => 1,
        'post__not_in' => $do_not_duplicate
        )
    );
    while ( have_posts() ) : the_post();?>
    <!--Do Stuff-->
    <?php endwhile; ?>

    The “category2” post doesn’t repeat, the problem is with “category2”

    This is probably not the right way to do it, but using ‘offset’ => 1 fix the problem for now.

    <article class="post" id="postmedium">
    <?php query_posts( array(
    	'category_name' => 'category1',
    	'posts_per_page' => 1,
    	'post__not_in' => $do_not_duplicate,
    	'offset' => 1
        )
    );
    while ( have_posts() ) : the_post();?>
    <!--Do Stuff-->
    <?php endwhile; ?>

    If somebody knows a better way, please let me know

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘multiples loops in interlayered categories without duplicates’ is closed to new replies.