Support

Account

Home Forums Add-ons Gallery Field Conditional to use animated gif in gallery

Helping

Conditional to use animated gif in gallery

  • Hey there,

    I was searching the forum and found this post:

    https://support.advancedcustomfields.com/forums/topic/conditional-to-use-full-image-size-with-animated-gifs/

    I’m wondering if it’s possible to do something similar within the gallery field. I have a client who wants to mix in animated gifs to a gallery and I would need to access the full size file for both the thumbnail and the large image, but I’m not sure how to do that within the gallery.

    Would appreciate any thoughts! Thanks!

  • Yup, you can definitely utilize similar conditional logic. The only thing that might affect it is that the size of your GIF could be way off from the size of the other images so you might need to regular that on the ACF upload end to make sure your user is uploading something of similar width/height.

    <?php
    $images = get_field( 'gallery' );
    $size = 'thumbnail';
    
    if ( $images ) : ?>
         <ul>
    
         <?php foreach ( $images as $image ) :
    			
         $url = $image["filename"];
         $filetype = wp_check_filetype( $url );
    
    	if ( 'gif' == $filetype['ext'] ) {
    		$url = $image['url'];
    	} else {
    		$url = $image['sizes'][$size];
    	} ?>
              <li><img src="<?php echo esc_url( $url ); ?>" alt="Text describing my image here" /></li>
         
         <?php endforeach; ?>
         
         </ul>
    <?php endif; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Conditional to use animated gif in gallery’ is closed to new replies.