Multiple loops in same page, without duplicate content

it is important to read this Codex chapter all the way to the end, as the essential suggestions are after this heading ‘Note for Multiple Posts in the First Category’;

repetitive, tedious code:

<?php   $do_not_duplicate = array(); ?>
<?php   $mosaics = new WP_Query('category_name=mosaics&posts_per_page=5'); ?>
<?php   while ($mosaics->have_posts()) : $mosaics->the_post(); ?>
<?php   $do_not_duplicate[] = $post->ID; ?>

<?php   echo get_the_content(); ?>
<?php   endwhile; wp_reset_postdata(); ?>

<br />

<?php   $mosaics = new WP_Query( array( 'category_name' => 'mosaics', 'posts_per_page' => 4, 'post__not_in' => $do_not_duplicate ) ); ?>
<?php   while ($mosaics->have_posts()) : $mosaics->the_post(); ?>
<?php   $do_not_duplicate[] = $post->ID; ?>
<?php   echo get_the_content(); ?>
<?php   endwhile; wp_reset_postdata(); ?>

<br />

<?php   $mosaics = new WP_Query( array( 'category_name' => 'mosaics', 'posts_per_page' => 3, 'post__not_in' => $do_not_duplicate ) ); ?>
<?php   while ($mosaics->have_posts()) : $mosaics->the_post(); ?>
<?php   $do_not_duplicate[] = $post->ID; ?>
<?php   echo get_the_content(); ?>
<?php   endwhile; wp_reset_postdata(); ?>

<br />

<?php   $mosaics = new WP_Query( array( 'category_name' => 'mosaics', 'posts_per_page' => 2, 'post__not_in' => $do_not_duplicate ) ); ?>
<?php   while ($mosaics->have_posts()) : $mosaics->the_post(); ?>
<?php   $do_not_duplicate[] = $post->ID; ?>
<?php   echo get_the_content(); ?>
<?php   endwhile; wp_reset_postdata(); ?>

Leave a Comment