Skip to content

Instantly share code, notes, and snippets.

@jhouedanou
Created March 10, 2015 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhouedanou/fa946a39affe2093ac75 to your computer and use it in GitHub Desktop.
Save jhouedanou/fa946a39affe2093ac75 to your computer and use it in GitHub Desktop.
Loop multiples sans posts dupliqués
<?php
$postsInCat = get_term_by('name','themes','category');
$postsInCat = $postsInCat->count;
//variable avec le nombre total de posts
$limite = 15;
$limitwhile = intval($postsInCat/$limite);
//echo $limitwhile;
?>
<!--premiere loop-->
<?php
$do_not_duplicate = array();
$i= 1;
while($i <= $limitwhile) {
?>
<?php $mosaics = new WP_Query(array('category_name'=>'themes','posts_per_page'=> 15, 'post__not_in' => $do_not_duplicate ) ); ?>
<?php if ( have_posts() ) :?>
<?php echo '<li id="contenu'.$i.'" class="leflah">'?>
<?php while ($mosaics->have_posts()) : $mosaics->the_post(); ?>
<?php $do_not_duplicate[] = $post->ID; ?>
<a href="<?php the_permalink();?>">
<?php the_title(); ?>
</a>
<?php endwhile; ?>
<?php echo '</li>'?>
<?php else :?>
<!--ne rien afficher-->
<?php endif; ?>
<?php wp_reset_postdata();
?>
<?php
$i++;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment