|
Joined: Mar 2008
Posts: 262
enthusiast
|
enthusiast
Joined: Mar 2008
Posts: 262 |
Was wondering if anyone had a quick and dirty way to change a image based on time of day. I have a image that we have a dark and light version of that we use in the top left corner of our site. We would like to have it change based on night and day.
|
|
|
|
Joined: Apr 2007
Posts: 3,940 Likes: 1
Former Developer
|
Former Developer
Joined: Apr 2007
Posts: 3,940 Likes: 1 |
in your header include
<?php
$t = getdate();
$hr = $t['hours'];
if ($hr > 12) { ?>
<img src="http://yoursite.com/path/to/image/beforenoon.jpg" />
<?php } else { ?>
<img src="http://yoursite.com/path/to/image/afternoon.jpg" />
<?php } ?>
for example or
<?php
$t = getdate();
$hr = $t['hours'];
if ($hr > 12) {
echo '<img src="http://yoursite.com/path/to/image/beforenoon.jpg" />';
} else {
echo '<img src="http://yoursite.com/path/to/image/afternoon.jpg" />';
}
?>
|
|
|
|
Joined: Mar 2008
Posts: 262
enthusiast
|
enthusiast
Joined: Mar 2008
Posts: 262 |
Hmm Not sure how I would changes this <a href="/html/indexgeorge2.shtml"><img border="0" src="/images/Messagerev.jpg" width="242" height="255"></a> to include that php code...
|
|
|
|
Joined: Jun 2006
Posts: 16,299 Likes: 116
|
Joined: Jun 2006
Posts: 16,299 Likes: 116 |
<?php
$t = getdate();
$hr = $t['hours'];
if ($hr > 12) {
echo '<a href="/html/indexgeorge2.shtml"><img border="0" src="/images/Messagerev.jpg" width="242" height="255" /></a>';
} else {
echo '<a href="/html/indexgeorge2.shtml"><img border="0" src="/images/Messagerev.jpg" width="242" height="255" /></a>';
}
?>
|
|
|
|
Joined: Jan 2004
Posts: 2,474 Likes: 3
Pooh-Bah
|
Pooh-Bah
Joined: Jan 2004
Posts: 2,474 Likes: 3 |
If you were using SD's second block of code - you would simply drop the entire string that you posted into this bit... ...although I would have thought that if $hr > 12 it would be the afternoon period. Is that right SD?
Last edited by driv; 01/21/2012 4:34 PM. Reason: Giz beat me to it....
|
|
|
|
Joined: Mar 2008
Posts: 262
enthusiast
|
enthusiast
Joined: Mar 2008
Posts: 262 |
So I would just replace the line I have in the middle of other code with the <?php....
|
|
|
|
Joined: Jan 2004
Posts: 2,474 Likes: 3
Pooh-Bah
|
Pooh-Bah
Joined: Jan 2004
Posts: 2,474 Likes: 3 |
Yes, the main page is php enabled (ubbthreads.php), so you just need the <?php and ?> tags to tell the php engine to do its thing.
(As opposed to just parsing regular text or HTML.)
|
|
|
|
Joined: Jan 2004
Posts: 2,474 Likes: 3
Pooh-Bah
|
Pooh-Bah
Joined: Jan 2004
Posts: 2,474 Likes: 3 |
I just popped SDs code into my default header and it worked just fine...
<?php
$t = getdate();
$hr = $t['hours'];
if ($hr > 12) {
echo 'night';
} else {
echo 'day';
}
?>
|
|
|
|
Joined: Apr 2007
Posts: 3,940 Likes: 1
Former Developer
|
Former Developer
Joined: Apr 2007
Posts: 3,940 Likes: 1 |
yup, i just had afternoon switched.. but you get the idea
|
|
|
|
Joined: Apr 2007
Posts: 3,940 Likes: 1
Former Developer
|
Former Developer
Joined: Apr 2007
Posts: 3,940 Likes: 1 |
i do the same thing in my header logo to swap in a different logo based upon holidays ( halloween, christmas, july 4 etc ) it can do even more, if you just imagine..
|
|
|
Bots
by Outdoorking - 04/13/2024 5:08 PM
|
|
|
|
|
|
1 members (Ruben),
1,248
guests, and
268
robots. |
Key:
Admin,
Global Mod,
Mod
|
|
|
|