Support

Account

Home Forums Add-ons Repeater Field Rotating Clickable Banner Code Reply To: Rotating Clickable Banner Code

  • Thanks for your response. I got some help, and here is the final code that we went with below. I’m not sure what the ’76’ does, but hope this helps others in the future.

    		<?php if( have_rows('title', 76) ): ?>
    			
    			<?php
    				// Get the repeater field
    				$repeater = get_field( 'title', 76 );
    
    				// Get a random row.
    				$random_row = array_rand( $repeater, 1 );
    
    				// Get subfields
    				$image = $repeater[$random_row]['image'];
    				$link =  $repeater[$random_row]['link'];
    			?>
    				<?php if( $link ): ?>
    					<a href="<?php echo $link; ?>">
    				<?php endif; ?>
    
    					<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
    
    				<?php if( $link ): ?>
    					</a>
    				<?php endif; ?>
    
    		<?php endif; ?>