February 24, 201016 yr I did a site for a client years ago and the header images are all in one folder and are randomised using this attached random.php file: rotate.php All pretty simple...but...The client wants the images to change depending on the saeson so, as the site was built ages ago when I was less savvy about dynamic content, I go into the site every season and switch the images in the folder to be the Spring, Summer, Autumn or Winter ones. It's a bit of a pain and even though I get paid to do this by the client I think it would be better if this was now made automatic. I wondered if I could use something like this: <img src="image/<? echo(date('F'))?>.jpg" /> and adapt it somehow so that instead of picking out images named by month it would picks out images named by saeson and also randomise them. Can anyone help as I'm a total novice when it comes to PHP. Thanks E
February 24, 201016 yr Author or maybe something could be added to the rotate.php file to make it do the randomisation according to season?
February 24, 201016 yr Author hi rallport - thanks for that - does that involve randomisation or the display of just one image? I need the images to randomise and there are 10 images for each season.
February 24, 201016 yr Author stumbling already - do I just put all this within opening and closing php tags? also how do I finish this off after I've listed all four seasons: } else ...etc. and where does this go: $yourRandomImage= $myImages[array_rand($myImages)]; echo $image22; and why does it have echo $image22; at the end?
February 24, 201016 yr // function to return season based on month function getseason($month) { switch($month) { case 12: case 1: case 2: $s = 'winter'; break; case 3: case 4: case 5: $s = 'spring'; break; case 6: case 7: case 8: $s = 'summer'; break; case 9: case 10: case 11: $s = 'autumn'; break; } return $s; } // Array of seasons and their image count $seasons = array( 'winter' => '10', 'spring' => '10', 'summer' => '10', 'autumn' => '10' ); $season = getseason(date('m')); $image = '<img src="images/'.$season.mt_rand(1, $seasons[$season]).'.jpg" alt="'.$season.'" />'; echo $image; The numbers in the seasons array are the maximum number for that season. Say winter has only 5 images, change the 10 to 5. Your images need to then be named winter1.jpg, winter2.jpg, winter3.jpg, winter4.jpg, and winter5.jpg. Note that the numbers start at 1 not 0
February 24, 201016 yr Author will digest this later - got to take the dog out in the howling wind / rain / sleat / snow - I may be some time...
February 24, 201016 yr lol we had the same thing yesterday...now it's sunny! Very strange weather patterns
Create an account or sign in to comment