Jump to content

[SOLVED] time based css style switcher doesnt work?


foevah

Recommended Posts

Hi I found this tutorial:

 

I edited the code (see below) and when it gets t evening the evening.css stylesheet doesnt load.. I have adjusted my time locally to check - morning and afternoon work but evening doesnt it displays default.css.. Can someone tell me why evening doesnt work?

 

<?php
// Get the current hour (24-hr clock)
$time = date('H');

// check to see if theme is passed in the URL and, if not,
// set it based on the current hour
if(!isset($_GET['theme'])) {
if($time >= '04' and $time < '12') {
$css = 'css/morning.css';
} elseif($time >= '12' and $time < '19') {
$css = 'css/afternoon.css';
} elseif($time >= '19' and $time < '04') {
$css = 'css/evening.css';
} else {
$css = 'css/default.css';
}
} else {
// if the theme is passed in the URL, specify a list of
// valid theme names
$themes = array('morning', 'afternoon', 'evening');

// if the theme is passed in the URL and the theme name
// is in the $themes array, set the theme; otherwise, throw an error
if($_GET['theme'] and in_array($_GET['theme'], $themes)) {
$css = 'css/' . $_GET['theme'] . '.css';
} else {
$error = TRUE;
echo 'You have specified an invalid theme.';
}
}
?>

idk but try this:

 

<?php
$time = date('G');
if (in_array($time,range(4,11))) $theme = 'morning';
elseif (in_array($time,range(12,18))) $theme = 'afternoon';
elseif (in_array($time,array(19,20,21,22,23,0,1,2,3))) $theme = 'evening';
else $theme = 'default';
$css = 'css/'.$theme.'.css';
?>

hi thanks for the quick response.. it seems to work on all 3 now. This code is much simplier.

 

The old code let me type this:

test.com/?theme=evening

 

and i could preview a theme like that.. this doesnt work with your new code is this because you took out the !isset ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.