Skip to content

Instantly share code, notes, and snippets.

@joshdavenport
Last active October 18, 2022 12:44
Show Gist options
  • Save joshdavenport/68ece5b3a8b19c8d13e2975fab927956 to your computer and use it in GitHub Desktop.
Save joshdavenport/68ece5b3a8b19c8d13e2975fab927956 to your computer and use it in GitHub Desktop.
<?php // -------- FOR METABOX FIELD TYPE `single_image` -------- ?>
<?php if($image = TGHPSite()->metabox->getSingleMetafieldValue('image')): ?>
<div class="intro__image">
<img src="<?= wp_get_attachment_image_url($image['ID'], 'original') ?>"
srcset="<?=
TGHPSite()->asset->getAttachmentSizesSrcset(
$image['ID'],
['xxs-uncropped','xs-uncropped','s-uncropped','m-uncropped','l-uncropped','xl-uncropped','xxl-uncropped','xxxl-uncropped','xxxxl-uncropped']
)
?>"
sizes="100vw
alt="<?= esc_attr(get_the_title()) ?>">
</div>
<?php endif ?>
<?php // -------- FOR METABOX FIELD TYPE `image_advanced` WITH MULTIPLE IMAGEs -------- ?>
<div class="gallery__items">
<?php foreach(TGHPSite()->metabox->getSingleMetafieldValue('images') as $image): ?>
<div class="gallery__image">
<img src="<?= wp_get_attachment_image_url($image['ID'], 'original') ?>"
srcset="<?=
TGHPSite()->asset->getAttachmentSizesSrcset(
$image['ID'],
['xxs-uncropped','xs-uncropped','s-uncropped','m-uncropped','l-uncropped','xl-uncropped','xxl-uncropped','xxxl-uncropped','xxxxl-uncropped']
)
?>"
sizes="100vw"
alt="<?= esc_attr(get_the_title()) ?>">
</div>
<?php endif ?>
</div>
<?php // -------- OR FOR A FEATURED IMAGE (POST THUMBNAIL) -------- ?>
<?php if ($image = get_post_thumbnail_id($caseStudy)): ?>
<img src="<?= wp_get_attachment_image_url($image, 'original') ?>"
srcset="<?=
TGHPSite()->asset->getAttachmentSizesSrcset(
$image,
['xxs-uncropped','xs-uncropped','s-uncropped','m-uncropped','l-uncropped','xl-uncropped','xxl-uncropped','xxxl-uncropped','xxxxl-uncropped']
)
?>"
sizes="(min-width: 1024px) 30vw, (min-width: 720px) 50vw, 100vw"
alt="<?= esc_attr($image) ?>">
<?php endif ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment