Home Forums Front-end Issues Hiding an empty repeater


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'); ?>
    				    <?php endwhile; ?>
    				<?php endif; ?>
  • 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
  • Thanks John that worked perfectly

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

The topic ‘Hiding an empty repeater’ is closed to new replies.