- array_rand: documentation ( source)
- floor: documentation ( source)
<section id="explore">
<div class="container-fluid">
<h2 class="white fs-h1">Explore</h2>
<div class="compass"></div>
</div> <!-- .container-fluid -->
<?php # Random fields.
$img_field = 3;//get_field('images');
$quotes_field = 5;//get_field('quotes');
# Long chain of destructuring to get random items from these:
if($img_field && $quotes_field):
$img_rand_keys = array_rand($img_field, 3);
$quotes_rand_keys = array_rand($quotes_field, 3);
$rand_imgs = [
$img_field[ $img_rand_keys[0] ]["image"],
$img_field[ $img_rand_keys[1] ]["image"],
$img_field[ $img_rand_keys[2] ]["image"],
];
$rand_quotes = [
$quotes_field[ $quotes_rand_keys[0] ]["quote"],
$quotes_field[ $quotes_rand_keys[1] ]["quote"],
$quotes_field[ $quotes_rand_keys[2] ]["quote"],
];
endif; # $img_field && $quotes_field ?>
<div class="explore-grid container">
<?php # For the 6 items..
for($i=0;$i<6;$i++):
if($i%2==0): // "Evens" ?>
<div class="grid-item grid-item--quote col">
<div class="fontawesome five-stars"></div>
<p>"<?php echo $rand_quotes[ floor(i/2) ] ?>"</p>
</div> <?
else: // "Odds" ?>
<div class="grid-item grid-item--image col">
<img src="<?php echo $rand_imgs[ floor(i/2) ] ?>" />
</div>
<?
endif; // if..else
endfor; // for($i=0..5) ?>
</div> <!-- .explore-grid -->
</section> <!-- #explore -->