Site Links
Home
Features
Documentation
Pricing & Order
Members Area
Support Options
UBBDev.com
UBBWiki.com
Who's Online
2 registered (Gizmo, SteveS), 38 Guests and 14 Spiders online.
Key: Admin, Global Mod, Mod
Featured Member
Registered: 06/07/07
Posts: 4
Top Posters (30 Days)
Ruben 50
DennyP 24
Gizmo 23
Dunny 15
SteveS 13
AllenAyres 12
dbremer 10
SD 10
drkknght00 9
doug 8
Latest Photos
OK Corral Shoot Out
Testing
Basildon Train Station
Basildon Town Centre looking from the rounderbout
Basildon Town Square
Topic Options
#248101 - 01/21/12 11:46 AM Change image based on time of day
Iann128 Offline

enthusiast
Registered: 03/21/08
Posts: 234
Loc: Austin, AR
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.
_________________________
Ian
http://www.firstgenmc.com/ubbthreads

"Experience is a hard teacher because she gives the test first, the lesson afterwords."
Top
Express Hosting
Express Hosting "We are the official hosting company of UBB.threads. Ask us about our free migration services to migrate your UBB.threads installation."
#248102 - 01/21/12 01:14 PM Re: Change image based on time of day [Re: Iann128]
SD Offline
Registered: 04/19/07
Posts: 4056
Loc: SoCal, USA
in your header include

Php Code:

<?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 Code:

<?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" />';
} 
?>

_________________________

Threads tutorials . Threads & Wordpress experts . UBB resume

If I you, click this link as to why
Top
#248105 - 01/21/12 02:51 PM Re: Change image based on time of day [Re: Iann128]
Iann128 Offline

enthusiast
Registered: 03/21/08
Posts: 234
Loc: Austin, AR
Hmm Not sure how I would changes this
Code:
<a href="/html/indexgeorge2.shtml"><img border="0" src="/images/Messagerev.jpg" width="242" height="255"></a>

to include that php code...
_________________________
Ian
http://www.firstgenmc.com/ubbthreads

"Experience is a hard teacher because she gives the test first, the lesson afterwords."
Top
#248108 - 01/21/12 03:27 PM Re: Change image based on time of day [Re: Iann128]
Gizmo Online   cat

Registered: 06/05/06
Posts: 14995
Loc: Portland, OR; USA
Php Code:


<?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>';
} 
?>


_________________________
Forums: UGN Security & VNC Web Design & Development
UBB.Threads: UBB.Wiki, My UBBSkins, UBB.Sitemaps
Longtime UBB Supporter, UBB Beta Tester & Resident Post-A-Holic.
UBB Modifications, Styling, Coding Services, Disaster Recovery, and more!
Top
#248110 - 01/21/12 03:33 PM Re: Change image based on time of day [Re: Iann128]
driv Offline

Pooh-Bah
Registered: 01/10/04
Posts: 2377
If you were using SD's second block of code - you would simply drop the entire string that you posted into this bit...

Code:
echo '';


...although I would have thought that if $hr > 12 it would be the afternoon period.

Is that right SD?



Edited by driv (01/21/12 03:34 PM)
Edit Reason: Giz beat me to it....
_________________________
Using version :: 7.5.6
Top
#248114 - 01/21/12 03:44 PM Re: Change image based on time of day [Re: Iann128]
Iann128 Offline

enthusiast
Registered: 03/21/08
Posts: 234
Loc: Austin, AR
So I would just replace the line I have in the middle of other code with the <?php....
_________________________
Ian
http://www.firstgenmc.com/ubbthreads

"Experience is a hard teacher because she gives the test first, the lesson afterwords."
Top
#248120 - 01/21/12 05:44 PM Re: Change image based on time of day [Re: Iann128]
driv Offline

Pooh-Bah
Registered: 01/10/04
Posts: 2377
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.)
_________________________
Using version :: 7.5.6
Top
#248121 - 01/21/12 05:47 PM Re: Change image based on time of day [Re: driv]
driv Offline

Pooh-Bah
Registered: 01/10/04
Posts: 2377
I just popped SDs code into my default header and it worked just fine... smile
Php Code:


<?php
$t = getdate();
$hr = $t['hours'];
if ($hr > 12) {
echo 'night';
} else {
echo 'day';
} 
?>


_________________________
Using version :: 7.5.6
Top
#248123 - 01/21/12 06:53 PM Re: Change image based on time of day [Re: Iann128]
SD Offline
Registered: 04/19/07
Posts: 4056
Loc: SoCal, USA
yup, i just had afternoon switched.. but you get the idea wink
_________________________

Threads tutorials . Threads & Wordpress experts . UBB resume

If I you, click this link as to why
Top
#248124 - 01/21/12 06:57 PM Re: Change image based on time of day [Re: Iann128]
SD Offline
Registered: 04/19/07
Posts: 4056
Loc: SoCal, USA
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..

wink
_________________________

Threads tutorials . Threads & Wordpress experts . UBB resume

If I you, click this link as to why
Top



Moderator:  AllenAyres, Harold, Ian, Ron M 
Shout Box

Today's Birthdays
No Birthdays
Recent Topics
Temporary Password email not being received
by
05/24/12 10:02 PM
Ability to "like" individual posts (not Facebook "likes)
by doug
05/23/12 09:03 AM
Island Permissions
by ThreadsUser
05/22/12 03:03 PM
streaming video
by prkrgrp
05/20/12 07:02 PM
New Posts Corrupted? Can someone help?
by PianoWorld
05/19/12 09:41 AM
Forum Stats
10492 Members
36 Forums
33842 Topics
181709 Posts

Max Online: 978 @ 06/24/07 11:19 PM
Random Image