Select Page

2 boucles wordpress exlude 1st post

28 Juin 2019 | loop, php, wordpress

Cette boucle permet par exemple d’avoir 2 boucles de post ou cpt.
Dans l’exemple la première boucle affiche 1 post et la seconde boucle 2 post. mais exlut le post de la boucle précédente en utilisant 'offset'=>1,

<div class="grid-container">
                <div class="row">
                    <?php         
                    $args = array( 'post_type' => 'project', 'posts_per_page' => 1, "order" => "DESC");
                    $query = new WP_Query( $args );
                    $cc = count($query);
                    if ( $query->have_posts() ) {
                    $i=0;
                    while ( $query->have_posts() ) { 
                    $query->the_post();?>
                    <div class="col-8">
                                        <div class="spacing50">
                                        	<img class="img-responsive" src="<?php the_post_thumbnail_url('full'); ?>" alt="">	
                                            <h1><?php the_title( );?></h1>
                                            <p><?php the_excerpt();?></p>
                                        </div>                          
                    </div><!--/.col-9-->       
                      <?php    $i++; 
                           }
                        }
                        wp_reset_query();
                        wp_reset_postdata();
                       ?>
                    <?php         
                    $args = array( 'post_type' => 'project', 'posts_per_page' => 2, 'offset'=>1, "order" => "DESC");
                    $query = new WP_Query( $args );
                    $cc = count($query);
                    if ( $query->have_posts() ) {
                    $i=0;
                    while ( $query->have_posts() ) { 
                    $query->the_post();?>
                    <div class="col-4">
                                        <div class="spacing50">
                                        	<img class="img-responsive" src="<?php the_post_thumbnail_url('custom-wide'); ?>" alt="">
                                            <h1><?php the_title( );?></h1>
                                            <p><?php the_excerpt();?></p>
                                        </div>                          
                    </div><!--/.testimonialitem-->       
                      <?php    $i++; 
                           }
                        }
                        wp_reset_query();
                        wp_reset_postdata();
                       ?>
 				</div>
  			</div>