Support

Account

Home Forums Front-end Issues Hiding an empty repeater

Solved

Hiding an empty repeater

  • I have been trying to hide this block of code if there are no links or text links to be displayed within the repeater, I need to hide the entire div, have tried wrapping with <?php if (get_sub_field(‘links-lister–text’)): ?> but no success

    	<div class="bg-light-grey-1 soft-double--ends">
    		
    		<div class="wrapper">
    			
    			<div class="col small-12">
    				
    				<h2 class="mega push--bottom">Related links</h2>
    					
    				<ul class="row">
    						
    				<?php if( have_rows('links-lister') ): ?>
    				 
    				    <?php while( have_rows('links-lister') ): the_row(); ?>
    				 				        
    						<li class="col small_12 small-medium_6 push--bottom">
    														
    							<a class="block" href="<?php the_sub_field('links-lister--link'); ?>">
    															
    								<?php the_sub_field('links-lister--text'); ?>
    																										
    							</a>
    																						
    						</li>
    				        
    				    <?php endwhile; ?>
    			 
    				<?php endif; ?>
    				
    				
    				</ul>
    				
    			</div>
    		
    		</div>
    		
    	</div>
    
  • you need to wrap your entire code block in the if( have_rows('links-lister') ):

    
    if( have_rows('links-lister') ):
    
      // the rest of your code goes here with the exception of repeating the IF statement
    
    endif;
    
  • Thanks John that worked perfectly

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.