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?
Background Image rotator
Re: Background Image rotator
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.
[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
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
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
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.
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.
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: Background Image rotator
jacek wrote:[syntax=php]
}else if ($date == '26-09'){
// Jacek's birthday
}[/syntax]
<?php while(!$succeed = try()); ?>
Re: Background Image rotator
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?
The code is already fully functioning?
Re: Background Image rotator
Fidbeck wrote:The code is already fully functioning?
Not sure what you mean by that The method above should work.
Re: Background Image rotator
What I meant is that Can I apply the code as it is?
I already have 3 functioning codes lol
I already have 3 functioning codes lol
Re: Background Image rotator
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
I haven't tried it but maybe I will get a fourth imagem rotator function