Jump to content

How to get different images display on page each day.


iconicCreator

Recommended Posts

With the help of the great people in here and some reading, I have managed to come up with a PHP script that displays random images every time a page loads or when user refreshes the page/browser. The script also echos a caption according to time of day.

 

Now I would like to modified the script so that instead of the image changing every time the page/browser refreshes, it will display a different image everyday with a caption.

 

So the script will display a different image everyday with a caption.

 

Now my current script displays images on reload/refresh with caption.

 

Here is the script.

 

<?php 
$images = array(
  array('file'    => 'image1a',
        'caption' => 'Good [PARTOFDAY]! <br /> My name is Rick. <br /> Welcome to B&I.'),
  array('file'    => 'image2a',
        'caption' => 'Good [PARTOFDAY]! <br /> My name is Dianna. <br /> Welcome to B&I.'),
  array('file'    => 'image3a',
        'caption' => 'Good [PARTOFDAY]! <br /> My name is David. <br /> Welcome to B&I.'),
  array('file'    => 'image4a',
        'caption' => 'Good [PARTOFDAY]! <br /> My name is Mariah. <br /> Welcome to B&I.'),
  array('file'    => 'image5a',
        'caption' => 'Good [PARTOFDAY]! <br /> My name is Gabriel. <br /> Thanks for visiting B&I.'),
	  array('file'    => 'image6a',
        'caption' => "Good [PARTOFDAY]! <br /> I'm Morrison. <br /> Thanks for visiting B&I.<br /> How can I help you?"),
	  array('file'    => 'image7a',
        'caption' => "Good [PARTOFDAY]! <br /> I'm Chris. <br /> Thanks for visiting B&I.<br /> Do you have a question?"),
	  array('file'    => 'image8a',
        'caption' => "Good [PARTOFDAY]! <br /> I'm Carlos. <br /> Welcome to B&I.<br /> How can I help you?"),
  );
$i = rand(0, count($images)-1);
$selectedImage = "../my_website_images/{$images[$i]['file']}.jpg";
$caption = $images[$i]['caption'];



function PARTOFDAY($string) {
$hour = date("H",time());
if($hour >= 6 && $hour < 12) $replace = 'morning';
elseif($hour >= 12 && $hour < 18) $replace = 'afternoon';
elseif($hour >= 18 && $hour < 24) $replace = 'evening';
else $replace = 'morning';
return str_replace("[PARTOFDAY]",$replace,$string);
} 
?>

 

Any ideas will be greatly appreciated.

 

Thanks everyone!

 

IC

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.