Support

Account

Home Forums Add-ons Repeater Field Repeater display Data on (2) Columns of a Table? Reply To: Repeater display Data on (2) Columns of a Table?

  • Hi @WPDragon

    I have whipped up some code which should produce the desired markup. Please take some time to read over and understand it line by line before using it:

    
    <?php
    
    $i = 0;
    
    if( have_rows('list_of_games') ): ?>
    
    	<table class="tg-table-plain">
    	
    	<?php while( have_rows('list_of_games') ): the_row(); $i++;
       
    		$post = get_sub_field('game_name'); 
    		
    		if( empty($post) )
    		{
    			continue;
    		}
    		
    		setup_postdata( $post );
       
    		?>
    
    		<?php if( $i == 1 ): ?>
    			<tr>
    		<?php endif; ?>
    		
    		<td>
    			<div class="image">
    				<img src= "<?php $image = get_sub_field('image'); echo $image['sizes']['medium']; ?>" />
    			</div>
    			<div class="title">
    				<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    			</div>
    			<div class="snippet">
    				<?php the_sub_field('game_snippet'); ?>
    			</div>
    			<div class="list-of-games">
    				<?php the_sub_field('list_of_games'); ?>
    			</div>
    		</td>
    
    		<?php if( $i == 2 ): $i = 0; ?>
    			</tr>
    		<?php endif; ?>
    		
      <?php endwhile; ?>  
      
      <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
             
    <?php endif; ?>
    

    Thanks
    E