Skip to content

Instantly share code, notes, and snippets.

@melissajclark
Last active May 12, 2016 14:59
Show Gist options
  • Save melissajclark/fd987f36c972f63d46bb1f1fd3960dc0 to your computer and use it in GitHub Desktop.
Save melissajclark/fd987f36c972f63d46bb1f1fd3960dc0 to your computer and use it in GitHub Desktop.
Random Hero Image Example
<?php
$images = get_field('hero_home_images');
if( $images ):
shuffle($images); // randomizes the image array
$max = 1; // set the max here;
$count = 0; // current count
?>
<?php
foreach( $images as $image ):
$count++; // increment count
// if count is greater than limt, stop showing images
if ($count > $max) {
break;
}
?>
<div class="hero hero--home" style="background-image:url(<?php echo $image['sizes']['hero']; ?>)">
<img class="hero--home__logo" src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/hero-logo.svg" alt="<?php esc_html_e('Mavericks VFX'); ?>">
<?php if ( get_field('hero_home_video_reel_pop_up') ) : ?>
<div class="hero--home__video"><?php the_field('hero_home_video_reel_pop_up'); ?></div>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment