Created
March 5, 2024 22:53
-
-
Save wplit/e8ff89069c0d3dadf9fe7cda04bfce2c to your computer and use it in GitHub Desktop.
output just images from acf photo gallery field, with 'cell' class on images
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 | |
global $post; | |
//Get the images ids from the post_metadata | |
$images = acf_photo_gallery('photo_gallery', $post->ID); | |
//Check if return array has anything in it | |
if( count($images) ): | |
//Cool, we got some data so now let's loop over it | |
foreach($images as $image): | |
$id = $image['id']; // The attachment id of the media | |
$title = $image['title']; //The title | |
$caption= $image['caption']; //The caption | |
$full_image_url= $image['full_image_url']; //Full size image url | |
$full_image_url = acf_photo_gallery_resize_image($full_image_url, 262, 160); //Resized size to 262px width by 160px height image url | |
$thumbnail_image_url= $image['thumbnail_image_url']; //Get the thumbnail size image url 150px by 150px | |
$url= $image['url']; //Goto any link when clicked | |
$target= $image['target']; //Open normal or new tab | |
//$alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields) | |
//$class = get_field('photo_gallery_class', $id); //Get the class which is a extra field (See below how to add extra fields) | |
?> | |
<?php if( !empty($url) ){ ?><a href="<?php echo $url; ?>" <?php echo ($target == 'true' )? 'target="_blank"': ''; ?>><?php } ?> | |
<img class="cell" src="<?php echo $full_image_url; ?>" alt="<?php echo $title; ?>" title="<?php echo $title; ?>"> | |
<?php if( !empty($url) ){ ?></a><?php } ?> | |
<?php endforeach; endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment