2

I'm using a custom subtheme of the Pixture Reloaded subtheme of Adaptivetheme. I want to change the theme colors based on the hour of the day. (I want a "day" theme and a "night" theme.)

I know that I can do this with the Themekey module, which allows you to specify rules for which theme to use. You can make a rule based on the time of day and have two different themes, but then I will have to maintain two entirely separate themes. Since all I want to change is the colors, taking this approach would be a maintenance nightmare.

Pixture Reloaded uses the Color module to allow users to select the colors, so I don't understand how to easily override it.

One thing I noticed is that there are a number of pre-defined color schemes. For my purposes, it would be sufficient to have a way to automatically use one pre-defined scheme during the day, and another at night.

How can I do this without creating (and maintaining) a copy of my original theme?

2

1 Answer 1

2

Place the following code into your theme's template.php file.

/**
* Implements template_preprocess_html().
*/
function YOUR_THEME_preprocess_html(&$vars) {
  // Day / night background theming.
  $hour = date('G');
  $theme = 'day';
  if ($hour <= 6) {
    $theme = 'night';
  }
  elseif ($hour >= 6 && $hour <= 18) {
    $theme = 'day';
  }
  elseif ($hour >= 18) {
    $theme = 'night';
  }
  $vars['classes_array'][] = $theme;
}

Now your <body> tag should have the CSS class 'day' or 'night' depending on the current server time.

An example CSS code would look like:

body.day {
  background: #fff;
  color: #000;
}
body.night {
  background: #000;
  color: #fff;
}

for more info check this tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.