Status
Not open for further replies.

jayfella

Active Member
Veteran
1,600
2009
565
680
This small snippet will allow you to use different color schemes (CSS stylesheets) depending on the time of the day! Its not a hugely complicated piece of code, but very creative! Most people have never even thought of the idea!


PHP:
<?php
   // If the time is past seven O'clock then use the  night stylesheet instead!
   if (date('G') > 19 || date('G') <  7) {
      echo '<link rel="stylesheet" type="text/css"  href="/static/css/default_night.css" />';
   } else {
       echo '<link rel="stylesheet" type="text/css"  href="/static/css/default_day.css" />';
   }
?>
 
15 comments
Do not forget that people that live in a different timezone than the one your server is on will most likely find it weird that the 'evening/night theme' would be turned on at like 10AM their time :D

EDIT: Nice share though :)
 
Would be cool if you could pull the users time zone that they picked at sign up and change it based on that. Would be I think 1-2 sql calls.

Thanks, I like the idea
 
The only downside of that is it'll always use server time. JavaScript can be an alternative to this, since you can fetch local time of the viewer.

Great work with all the posts and tutorials jay. <3

PHP:
//Alternative 1
$css =  date('G') > 19 || date('G') <  7 ? 'default_night.css' : 'default_day.css';
echo '<link rel="stylesheet" type="text/css"  href="/static/css/'.$css.'" />';

//Alternative 2
echo date('G') > 19 || date('G') <  7 ? '<link rel="stylesheet" type="text/css"  href="/static/css/default_night.css" />' : '<link rel="stylesheet" type="text/css"  href="/static/css/default_day.css" />';
 
yah, a great use of the js woud be maybe showing like a brighter, sunny type banner during the day, and switching to a night one during the night. Its not a big change, nor is it hard to implement, but it looks great :)
 
I remember some sites were showing my current time(from my computer) is there a way to implement that code into this one?


Good work (y)
 
well, I've modify the code for the CSS stylesheets to change everyday.

here is the sample for phpbb

PHP:
<link href="{T_THEME_PATH}/
<!-- PHP -->
$today = Date('D');
switch ($today){
    case 'Mon';
        echo 'style1.css';
    breaK;
    case 'Tue';
        echo 'style2.css';
    breaK;
    case 'Wed';
        echo 'style3.css';
    breaK;
    case 'Thu';
        echo 'style4.css';
    breaK;
    case 'Fri';
        echo 'style5.css';
    breaK;
    case 'Sat';
        echo 'style6.css';
    breaK;
    default;
        echo 'style1.css';
    breaK;
}
<!-- ENDPHP -->
" rel="stylesheet" type="text/css" media="screen, projection" />
 
what about a javascript touch?

Code:
<script language="javascript">
<!--
Stamp = new Date();

var Hours;
Hours = Stamp.getHours();
if (Hours >= 7 && Hours < 19) {
document.write('<link rel="stylesheet" type="text/css"  href="/static/css/default_dayt.css" />');
}
else {
document.write('<link rel="stylesheet" type="text/css"  href="/static/css/default_night.css" />');
}

//-->
</script>
 
Your best of using javascript for this, unless your detecting the users timezone and using PHP's functionality such as set_timezone() etc.. because me and jay would see a day version but people in other countries will see the day version even if it is night time !
 
As someone pointed out it would only show the server time.

I will take vb as an example, say your forum time is set differently you can use the var $vboptions[timeoffset] - which is the forum time offset

(im sure there is one for users which will fix the issue of users with different time zones)

Anyways good code jay, most of these ive seen is in javascript.
 
Status
Not open for further replies.
Back
Top