Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Created October 19, 2017 22:08
Show Gist options
  • Save damiencarbery/3f7f36eb5fecb70cd83fb0dec4a97929 to your computer and use it in GitHub Desktop.
Save damiencarbery/3f7f36eb5fecb70cd83fb0dec4a97929 to your computer and use it in GitHub Desktop.
<?php
$images = get_field('photos');
if ($images) { ?>
<div class="images">
<?php
$alt = $images[0]['alt'];
if (empty($alt)) {
$alt = $images[0]['title'];
}
printf('<a href="%s" itemprop="image" class="main-image zoom thickbox" title="" rel="prettyPhoto[gallery] gallery"><img width="%d" height="%d" src="%s" class="attachment-shop_single size-shop_single wp-post-image" alt="%s" title="%s" /></a>',
$images[0]['url'], $images[0]['sizes']['featured-image-width'], $images[0]['sizes']['featured-image-height'], $images[0]['sizes']['featured-image'], $alt, $images[0]['title']);
if (count($images) > 1) {
$images = array_slice($images, 1); // Remove first element as it has been output as main image.
?>
<div class="thumbnails">
<?php
foreach ($images as $image) {
$alt = $image['alt'];
if (empty($alt)) {
$alt = $image['title'];
}
printf('<a href="%s" class="zoom thickbox" title="" rel="prettyPhoto[gallery] gallery"><img width="%d" height="%d" src="%s" class="attachment-shop_thumbnail size-shop_thumbnail" alt="%s" title="%s" /></a>',
$image['url'], $image['sizes']['thumbnail-width'], $image['sizes']['thumbnail-height'], $image['sizes']['thumbnail'], $alt, $image['title']);
} // End: foreach ($images as $image)
?>
</div>
<?php
} // End: if (count($images) > 1) ?>
</div>
<?php } // End: if ($images) ?>
</div>
<?php
global $post;
$inflatable_info = get_post_meta( $post->ID );
$images = maybe_unserialize( $inflatable_info[ 'photos' ][ 0 ] );
if ($images) { ?>
<div class="images">
<?php
$uploads_dir = wp_get_upload_dir()['baseurl'];
$featured_image = get_post_meta( $images[ 0 ] );
$image_meta = maybe_unserialize( $featured_image[ '_wp_attachment_metadata' ][ 0 ] );
$image_dir = $uploads_dir . '/' . dirname( $image_meta[ 'file' ] );
$alt = '';
if ( array_key_exists( '_wp_attachment_image_alt', $featured_image ) ) {
$alt = esc_html( $featured_image[ '_wp_attachment_image_alt' ][ 0 ] );
}
$title = get_the_title( $images[ 0 ] );
printf('<a href="%s" itemprop="image" class="main-image zoom thickbox" title="" rel="prettyPhoto[gallery] gallery"><img width="%d" height="%d" src="%s" class="attachment-shop_single size-shop_single wp-post-image" alt="%s" title="%s" /></a>',
esc_url( $uploads_dir .'/'. $image_meta[ 'file' ] ),
esc_html( $image_meta['sizes']['featured-image'][ 'width' ] ), esc_html( $image_meta['sizes']['featured-image'][ 'height' ] ), esc_url( $image_dir .'/'. $image_meta['sizes']['featured-image'][ 'file' ] ),
$alt, $title);
if (count($images) > 1) {
$images = array_slice($images, 1); // Remove first element as it has been output as main image.
?>
<div class="thumbnails">
<?php
foreach ( $images as $image ) {
$image_info = get_post_meta( $image );
echo '<!-- ', var_export( $image_info, true ), " -->\n";
$image_meta = maybe_unserialize( $image_info[ '_wp_attachment_metadata' ][ 0 ] );
$image_dir = $uploads_dir . '/' . dirname( $image_meta[ 'file' ] );
$alt = '';
if ( array_key_exists( '_wp_attachment_image_alt', $image_info ) ) {
$alt = esc_html( $image_info[ '_wp_attachment_image_alt' ][ 0 ] );
}
$title = get_the_title( $images[ 0 ] );
printf('<a href="%s" itemprop="image" class="main-image zoom thickbox" title="" rel="prettyPhoto[gallery] gallery"><img width="%d" height="%d" src="%s" class="attachment-shop_single size-shop_single wp-post-image" alt="%s" title="%s" /></a>',
esc_url( $uploads_dir .'/'. $image_meta[ 'file' ] ),
esc_html( $image_meta['sizes']['thumbnail'][ 'width' ] ), esc_html( $image_meta['sizes']['thumbnail'][ 'height' ] ), esc_url( $image_dir .'/'. $image_meta['sizes']['thumbnail'][ 'file' ] ),
$alt, $title);
}
?>
</div>
<?php
} // End: if (count($images) > 1) ?>
</div>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment