Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP - Image Holiday Swapper

PHP - Image Holiday Swapper
Thread Tools
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Sep 25, 2003, 01:47 AM
 
I'm looking for a script I can put in one of my sites to automatically swap the normal main image with a special one for the holiday. You know so around christmas you'll get my xmass image and around holloween you'll get my holloween image. Kinda like google does only I want a script to automate it. I'd like to be editable so I can do custom stuff (like leave the decorations up after Christmas but not turn the lights on :-) )
     
Registered User
Join Date: Jul 2003
Location: San Jose
Status: Offline
Reply With Quote
Sep 25, 2003, 03:55 AM
 
this will change the pic depending on the month...

[php]<?

// current month
$month = date(n);

switch ("$month") {

case 10:
$pic = "images/halloween.jpg";
break;

case 12:
$pic = "images/xmas.jpg";
break;

default:
$pic = "images/not-a-holiday.jpg";
break;
}

?>

<html>

<head></head>

<body>

<img src="<? echo "$pic"; ?>">

</body>

</html>[/php]
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Sep 25, 2003, 04:03 AM
 
Can you come up with something more specific? I don't want pumpkins and ghosts the whole month of october. And for valentines day, i'd only want my *dirty* logo up for just that day, for instance. Those holidays that are not always on the same day each year will be extra tricky too
     
Xeo
Moderator Emeritus
Join Date: Mar 2001
Location: Austin, MN, USA
Status: Offline
Reply With Quote
Sep 25, 2003, 04:18 AM
 
Figure out what range of dates you want these things to happen in between. Then use the date() function to determine which range the current day falls in and use switch() to choose between images.
     
Registered User
Join Date: Jul 2003
Location: San Jose
Status: Offline
Reply With Quote
Sep 25, 2003, 04:59 AM
 
Originally posted by l008com:
Can you come up with something more specific?
woo hoo... one more to 100

[php]
<?

// holiday [ start, end ]
$xmas = array(15, 31);
$valentines = 14;

// current [ month, day ]
$today = array(date(n), date(j));

switch ("$today[0]") {

case 2:
if ("today[1]" == "$valentines")
{
$pic = "images/valentines.jpg";
} else {
$pic = "images/not-a-holiday.jpg";
}
break;

case 12:
if ("$today[1]" > "$xmas[0]" && "$today[1]" < "$xmas[1]")
{
$pic = "images/xmas.jpg";
} else {
$pic = "images/not-a-holiday.jpg";
}
break;

default:
$pic = "images/not-a-holiday.jpg";
break;
}

?>

<html>

<head></head>

<body>

<img src="<? echo "$pic"; ?>">

</body>

</html>[/php]
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 07:12 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2