Page 1 of 1

Background Image rotator

Posted: Fri Dec 07, 2012 5:54 pm
by Fidbeck
What's the best way to create an automatic image background rotator?
I mean from January 1st to 21st of March have a winter related image background and from 22nd of March to 21st of august haver spring image and so on.
for the specific dates is better to use a case statement of an if statement?

Re: Background Image rotator

Posted: Sun Dec 09, 2012 9:55 pm
by jacek
I would names the images based on their date like "background_01-01.jpg" then you can use date()

[syntax=php]<img src="background_<?php echo date('d-m'); ?>.jpg" alt="bg" />[/syntax]
That way it will be easy to change one of the images.

Re: Background Image rotator

Posted: Sun Dec 09, 2012 9:58 pm
by Fidbeck
Care to elaborate?
And if I want to change to different pics in specific days like Christmas, New Year, Easter, Halloween and so on xD

Re: Background Image rotator

Posted: Sun Dec 09, 2012 10:04 pm
by jacek
Oh I think I misread, The above would give you a background unique to each day. If you only want a few variations for random lengths of time it probably is best to use a if else if else

Something like this

[syntax=php]$date = date('d-m');
$month = date('m');

if ($date == '25-12'){
// xmas one
}else if ($date == '26-09'){
// Jacek's birthday
}else if ($month < 3){
// winter
}else if ($month < 6){
// spring
}else{
// default
}[/syntax]
add as many as you need.

You could also use the date comparison functions to be more accurate.

Re: Background Image rotator

Posted: Sun Dec 09, 2012 10:06 pm
by ExtremeGaming
jacek wrote:[syntax=php]
}else if ($date == '26-09'){
// Jacek's birthday
}[/syntax]


:lol:

Re: Background Image rotator

Posted: Sun Dec 09, 2012 10:08 pm
by Fidbeck
Since this is for the Nucleus of Students of my faculty I have to add 2 dates, faculty and university's aniversaries.
The code is already fully functioning?

Re: Background Image rotator

Posted: Fri Dec 14, 2012 12:40 am
by jacek
Fidbeck wrote:The code is already fully functioning?

Not sure what you mean by that :? The method above should work.

Re: Background Image rotator

Posted: Fri Dec 14, 2012 12:33 pm
by Fidbeck
What I meant is that Can I apply the code as it is?
I already have 3 functioning codes lol

Re: Background Image rotator

Posted: Sat Dec 29, 2012 1:45 am
by jacek
Fidbeck wrote:What I meant is that Can I apply the code as it is?
I already have 3 functioning codes lol

You would have to change the dates and links for your case but pretty much.

Sorry for the delay :(

Re: Background Image rotator

Posted: Thu Jan 03, 2013 6:03 pm
by Fidbeck
I haven't tried it but maybe I will get a fourth imagem rotator function :P