Created
July 3, 2018 05:17
-
-
Save patric-boehner/9b43eea6580cd0ebc9a03019a17ba884 to your computer and use it in GitHub Desktop.
A header gallery with different image sizes based on position to reduce file size.
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 | |
// Don't include opening php tag | |
// Cmb2 meta feild prefix | |
$prefix = '_homepage_header_gallery_' | |
// Get the list of files | |
$files = get_post_meta( get_the_ID(), $prefix . 'images', 1 ); | |
echo '<div class="header-image-collage-wrap">'; | |
// Loop through them and output an image | |
$counter = 0; | |
foreach ( (array) $files as $attachment_id => $attachment_url ) { | |
$full = array( 0, 3 ); | |
$half = array( 1, 2, 4, 5, 6, 7 ); | |
if ( in_array( $counter, $full ) ) { | |
$image_size_name = 'header-image'; | |
$img_size = 'header-image'; | |
} elseif ( in_array( $counter, $half ) ) { | |
$image_size_name = 'medium'; | |
$img_size = 'medium'; | |
} | |
echo '<div class="collage-image image-size_'.$image_size_name.'">'; | |
echo wp_get_attachment_image( $attachment_id, $img_size ); | |
echo '</div>'; | |
$counter++; | |
} | |
echo '</div>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment