$leadimage = get_field('lead_image');
$bot_first_img = get_field('image_#1');
$bot_second_img = get_field('image_#2');
$bot_third_img = get_field('image_#3');
//Lead Image
$url = $leadimage['url'];
$title = $leadimage['title'];
$alt = $leadimage['alt'];
$caption = $leadimage['caption'];
//Bot Img 1
$url1 = $first_img['url'];
$title1 = $first_img['title'];
$alt1 = $first_img['alt'];
$caption1 = $first_img['caption'];
//Bot Img 2
$url2 = $second_img['url'];
$title2 = $second_img['title'];
$alt2 = $second_img['alt'];
$caption2 = $second_img['caption'];
//Bot Img 3
$url2 = $second_img['url'];
$title2 = $second_img['title'];
$alt2 = $second_img['alt'];
$caption2 = $second_img['caption'];
//Lead Image
$size = 'lead-custom-size';
$thumb = $leadimage['sizes'][ $size ];
$width = $leadimage['sizes'][ $size . '-width' ];
$height = $leadimage['sizes'][ $size . '-height' ];
//Bot Img 1
$size3 = 'circle-thumbnail-small';
$thumb3 = $bot_first_img['sizes'][ $size3 ];
$width3 = $bot_first_img['sizes'][ $size3 . '-width' ];
$height3 = $bot_first_img['sizes'][ $size3 . '-height' ];
//Bot Img 2
$size4 = 'circle-thumbnail-small';
$thumb4 = $bot_second_img['sizes'][ $size4 ];
$width4 = $bot_second_img['sizes'][ $size4 . '-width' ];
$height4 = $bot_second_img['sizes'][ $size4 . '-height' ];
//Bot Img 3
$size5 = 'circle-thumbnail-small';
$thumb5 = $bot_third_img['sizes'][ $size5 ];
$width5 = $bot_third_img['sizes'][ $size5 . '-width' ];
$height5 = $bot_third_img['sizes'][ $size5 . '-height' ];
function getImageData($name, $size) {
$data = get_field($name);
return array_merge($data, [
'thumb' => $data['sizes'][$size],
'width' => $data['sizes'][$size . '-width'],
'height' => $data['sizes'][$size . '-height'],
]);
}
$image = getImageData('lead_image', 'lead-custom-size');
// view.php
<img src="<?= $image['url'] ?>" height="<?= $image['height'] ?>" width="<?= $image['width'] ?>">
git commit -m 'finally got this shit beautified'
// sarcasm begin
// Refactored!
_
_( )_
(_(%)_)
(_)\
| __
|/_/
|
|
$leadimage = get_field('lead_image');
$bot_first_img = get_field('image_#1');
$bot_second_img = get_field('image_#2');
...
// sarcasm end
for $i = 0; i <= 3; $i ++) {
${'image'.$i} = get_field('image_#' . $i);
${'url'.$i} = ${'image'.$i}['url'];
${'title'.$i} = ${'image'.$i}['title'];
${'alt'.$i} = ${'image'.$i}['alt'];
${'caption'.$i} = ${'image'.$i}['caption'];
${'size'.$i} = ($i === 0) ? 'lead-custom-size' : 'circle-thumbnail-small';
${'thumb'.$i} = ${'image'.$i}['sizes'][ ${'size'.$i} ];
${'width'.$i} = ${'image'.$i}['sizes'][ ${'size'.$i} . '-width' ];
${'width'.$i} = ${'image'.$i}['sizes'][ ${'size'.$i} . '-height' ];
}