• Resolved bibliofille

    (@bibliofille)


    I’m using ACF Pro repeater field on this page: https://www.test.truetolifetraining.com/colleges-universities

    Within each content block, there’s an option to add an image or a video. When the video field is left blank, it’s fine, however, when the image field is left blank, a tiny square shows up above the video.

    I’m trying to figure out how to hide the image field if it is left blank, but I’m not sure how to do that within a repeater. Here’s the code from my page template:

    <?php if( have_rows('content_block') ): ?>
    
    	<?php while( have_rows('content_block') ): the_row(); 
    
    		// vars
    		$title = get_sub_field('title');
    		$content = get_sub_field('content');
    		$image = get_sub_field('image');
    		$video = get_sub_field('video');
    
    		?>
    <div class="content-block-item">
    
    				<div class="content-block-inner"><h4> <?php echo $title; ?></h4>
    			    <p><?php echo $content; ?></p>
    			    <div class="content-block-photo"><img src="<?php echo $image['url']; ?>"/></div>
    			    <div class="video"><?php echo $video;?></div>
    			    <button><a href="mailto:[email protected]">get in touch to learn more</a></button>
    			</div>
    
    		</div>
    
    	<?php endwhile; ?>
    
    <?php endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi bibliofille, Try the below code once

    <?php if( have_rows('content_block') ): ?>
    
    	<?php while( have_rows('content_block') ): the_row(); 
    
    		// vars
    		$title = get_sub_field('title');
    		$content = get_sub_field('content');
    		$image = get_sub_field('image');
    		$video = get_sub_field('video');
    
    		?>
    <div class="content-block-item">
    
    				<div class="content-block-inner"><h4> <?php echo $title; ?></h4>
    			    <p><?php echo $content; ?></p>
    			    <?php  if($image['url'] != ''){ ?>
    				<div class="content-block-photo"><img src="<?php echo $image['url']; ?>"/></div>
    				<?php } ?>
    			    <div class="video"><?php echo $video;?></div>
    			    <button><a href="mailto:[email protected]">get in touch to learn more</a></button>
    			</div>
    
    		</div>
    
    	<?php endwhile; ?>
    
    <?php endif; ?>

    let me know if it works for you.

    Thread Starter bibliofille

    (@bibliofille)

    Wait, spoke too soon. That didn’t quite work.

    can you share page link or screenshot of what error you see ?

    Thread Starter bibliofille

    (@bibliofille)

    I can’t attach a screenshot here, but here’s the link to the page: https://www.test.truetolifetraining.com/colleges-universities/

    In the content blocks where’s there’s a video instead of an image, it creates an empty img tag that not only throws off the layout, but creates a teeny tiny square.

    Funny thing is, it doesn’t show up on mobile though.

    It seems like the <img> tag is coming from the content of ACF field, can you check it once.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hiding empty field within ACF Repeater loop’ is closed to new replies.