Last active
July 1, 2020 20:15
-
-
Save eclarrrk/40c3f78490f618b86739f17e3ebc6dd9 to your computer and use it in GitHub Desktop.
Using the ACF Repeater field to make all images in a row the same height regardless of dimensions or the quantity of images per row
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if( have_rows('gallery') ): ?> | |
<div class="gallery"> | |
<?php while( have_rows('gallery') ): the_row(); ?> | |
<div class="gallery__row" style="display: flex;"> | |
<?php if( have_rows('image_row') ): ?> | |
<?php while( have_rows('image_row') ): the_row(); ?> | |
<?php | |
$imgID = get_sub_field('image'); // get image ID | |
$img_attrs = wp_get_attachment_image_src( $imgID, 'full' ); // get image attributes array | |
$img_width = $img_attrs[1]; // get width | |
$img_height = $img_attrs[2]; // get height | |
$img_ratio = $img_width / $img_height; // calculate flex value touse as inline style | |
?> | |
<div class="gallery__item" style="flex: <?php echo $img_ratio ?>"> | |
<?php echo wp_get_attachment_image($imgID, 'full'); ?> | |
</div> | |
<?php endwhile; ?> | |
<?php endif;?> | |
</div> <!-- end .gallery__row --!> | |
<?php endwhile;?> | |
</div> <!-- end .gallery --!> | |
<?php endif;?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment