Created
July 7, 2025 13:22
-
-
Save Firsh/0363205d66c6f1cfddfc9147b4181e1f to your computer and use it in GitHub Desktop.
Periodically random JIG
This file contains hidden or 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 | |
add_filter('jig_images', 'jig_periodically_random_images', 10, 2); | |
function jig_periodically_random_images($images, $atts) { | |
// Only apply to a specific grid, e.g. with a custom_class | |
if (empty($atts['custom_class']) || $atts['custom_class'] !== 'periodically-random') { | |
return $images; | |
} | |
$total = count($images); | |
$show = 7; // Number of images to display | |
// Change this to control how often the set changes: | |
$hours = 1; | |
$period = floor(time() / (60 * 60 * $hours)); | |
$seed = date('Y-m-d') . '-' . $period; | |
// Deterministically shuffle using the seed | |
mt_srand(crc32($seed)); | |
$indices = range(0, $total - 1); | |
shuffle($indices); | |
// Pick the first $show indices | |
$selected = array_slice($indices, 0, $show); | |
// Build the new images array | |
$new_images = []; | |
foreach ($selected as $i) { | |
$new_images[] = $images[$i]; | |
} | |
// Reset the random seed to avoid affecting other code | |
mt_srand(); | |
return $new_images; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment