I want to show a random background image, that starts a loop of random other background images after five seconds.
First I create an array for my background-images:
<?php
$bg = array('bg1.jpg', 'bg2.jpg', 'bg3.jpg', 'bg4.jpg', 'bg5.jpg', 'bg6.jpg', 'bg7.jpg', 'bg8.jpg', 'bg9.jpg', 'bg10.jpg', 'bg11.jpg');
$i = rand(0, count($bg)-1);
$selectedBg = "$bg[$i]";
?>
Second I append a random image to my body:
<style>
@media screen and (min-width: 600px) {
body {
background-image: url(<?php bloginfo('template_url'); ?>/images/backgrounds/<?php echo $selectedBg; ?>);
}
}
</style>
Now I would like to use php
or jQuery
to select another random image and change the background. How can I achieve this?