Support

Account

Home Forums Front-end Issues 2 loops in a DIVI template page Reply To: 2 loops in a DIVI template page

  • Ok, i resolve myself my problem.
    My new code is :

    <?php
    
    /*
    Template Name: Comptes rendus
    */
    
    get_header();
    
    $show_default_title = get_post_meta( get_the_ID(), '_et_pb_show_title', true );
    
    $is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() );
    
    ?>
    
    <div id="main-content">
    	<?php
    		if ( et_builder_is_product_tour_enabled() ):
    			// load fullwidth page in Product Tour mode
    			while ( have_posts() ): the_post(); ?>
    
    				<article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post' ); ?>>
    					<div class="entry-content">
    					<?php
    						the_content();
    					?>
    					</div> <!-- .entry-content -->
    
    				</article> <!-- .et_pb_post -->
    
    		<?php endwhile;
    		else:
    	?>
    	<div class="container">
    		<div id="content-area" class="clearfix">
    			<div id="left-area">
    			<?php while ( have_posts() ) : the_post(); ?>
    				<?php
    				/**
    				 * Fires before the title and post meta on single posts.
    				 *
    				 * @since 3.18.8
    				 */
    				do_action( 'et_before_post' );
    				?>
    				<article id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_post' ); ?>>
    					<?php if ( ( 'off' !== $show_default_title && $is_page_builder_used ) || ! $is_page_builder_used ) { ?>
    						<div class="et_post_meta_wrapper">
    							<h1 class="entry-title"><?php the_title(); ?></h1>
    						</div> <!-- .et_post_meta_wrapper -->
    				<?php  } ?>
    
    					<div class="entry-content">
    					<?php
    						do_action( 'et_before_content' );
    			
    
    $query2021 = new WP_Query( array( 
    'post_type' => 'comptes-rendus',
    'orderby' => 'date',
    'order'   => 'DESC',
    'meta_query' => array(
    						array( 
    						'key' => 'annee', // name of custom field
    						'value' => '2021', // matches exaclty "123", not just 123. This prevents a match for "1234"
    						'compare' => 'LIKE' 
    					)
    )
    )
    );
    						// The Query
    if ( $query2021->have_posts() ) : ?>
    <div class="entry-content" itemprop="text">
    <table class="table-cr">
      <thead>
        <tr>
          <th scope="col">Intitulé</th>
          <th scope="col">Date</th>
          <th scope="col">Fichier</th>
          <th scope="col">Poids</th>
        </tr>
      </thead>
    <?php // The Loop
    $file = get_field('fichier');
    while ( $query2021->have_posts() ) : $query2021->the_post(); ?>
      <tbody>
        <tr>
          <td data-label="Intitulé"><?php the_field('intitule'); ?></td>
          <td data-label="Date"><?php the_time( 'j.m.Y' ); ?></td>
          <td data-label="Fichier"><a href="<?php the_field('fichier'); ?>" target="_blank" ><button>Télécharger</button></a></td>
    	  <td data-label="Poids"><?php the_field('poids'); ?></td>
        </tr>
    
    </tbody>
    <? endwhile; ?>
    </table>
    </div>
    <?php endif ;
    
    $query2020 = new WP_Query( array( 
    'post_type' => 'comptes-rendus',
    'orderby' => 'date',
    'order'   => 'DESC',
    'meta_query' => array(
    						array( 
    						'key' => 'annee', // name of custom field
    						'value' => '2020', // matches exaclty "123", not just 123. This prevents a match for "1234"
    						'compare' => 'LIKE' 
    					)
    )
    )
    );
    						// The Query
    if ( $query2020->have_posts() ) : ?>
    <div class="entry-content" itemprop="text">
    <table class="table-cr">
      <thead>
        <tr>
          <th scope="col">Intitulé</th>
          <th scope="col">Date</th>
          <th scope="col">Fichier</th>
          <th scope="col">Poids</th>
        </tr>
      </thead>
    <?php // The Loop
    $file = get_field('fichier');
    while ( $query2020->have_posts() ) : $query2020->the_post(); ?>
      <tbody>
        <tr>
          <td data-label="Intitulé"><?php the_field('intitule'); ?></td>
          <td data-label="Date"><?php the_time( 'j.m.Y' ); ?></td>
          <td data-label="Fichier"><a href="<?php the_field('fichier'); ?>" target="_blank" ><button>Télécharger</button></a></td>
    	  <td data-label="Poids"><?php the_field('poids'); ?></td>
        </tr>
    
    </tbody>
    <? endwhile; ?>
    </table>
    </div>
    <?php endif; wp_reset_postdata(); ?>
    					
    					
    					</div> <!-- .entry-content -->
    					<div class="et_post_meta_wrapper">
    					<?php
    					
    					/**
    					 * Fires after the post content on single posts.
    					 *
    					 * @since 3.18.8
    					 */
    					do_action( 'et_after_post' );
    
    						
    					?>
    					</div> <!-- .et_post_meta_wrapper -->
    				</article> <!-- .et_pb_post -->
    
    			<?php endwhile; wp_reset_postdata(); ?>
    			
    			</div> <!-- #left-area -->
    
    			<?php get_sidebar(); ?>
    		</div> <!-- #content-area -->
    	</div> <!-- .container -->
    	<?php endif; ?>
    </div> <!-- #main-content -->
    
    <?php
    
    get_footer();

    Thank you !