Jump to content

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 ?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.