I have a list of images and I have a wordpress loop.
I use the randompics() function to generate a random image to use as a background to the prreview link. However, Im finding that Im generating repeat images here and there and it doesnt look great.
I would like to find a way to ensure that I dont have the same image more than once. There are only ever 10 iterations of the loop on any one page.
Here is my function.
function randompics() {
$arrayName = array(
get_template_directory_uri().'/images/jobs_large/1.jpg',
get_template_directory_uri().'/images/jobs_large/2.jpg',
get_template_directory_uri().'/images/jobs_large/3.jpg',
get_template_directory_uri().'/images/jobs_large/4.jpg',
get_template_directory_uri().'/images/jobs_large/5.jpg',
get_template_directory_uri().'/images/jobs_large/6.jpg',
get_template_directory_uri().'/images/jobs_large/7.jpg',
get_template_directory_uri().'/images/jobs_large/8.jpg',
get_template_directory_uri().'/images/jobs_large/9.jpg',
get_template_directory_uri().'/images/jobs_large/11.jpg',
get_template_directory_uri().'/images/jobs_large/12.jpg',
//list goes up to 25 images
);
echo $arrayName[array_rand($arrayName)];
}
Heres my loop
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="item-container">
<?php randompics(); ?>
</div>
<?php endwhile; else : endif;?>
Thanks in advance.
randompics($index);without usingarray_rand()I mean?