Hello Everyone and Happy New Year to you and all users. Just had Thought while updating one of my site. I just wonder, whether it is possible to have multiple themes installted in html directory and then activating them from the admin or even let site users choose theme on the fly.
I was thinking creating multiple folders with theme names in /html/ like "RED" "BLUE" "YELLOW" etc and modify the script detect these folders give either admin or users (depnding on the setup) option to choose which one to use.
Only thing I don't know is how complex this will be interms of script modification.
Your feedsback is really welcome.
Hi,
If the difference between themes could be managed entire within CSS, it would just be a matter of switching the default.css included by html/header.php based on a user preference, which could be quite easily managed via a cookie, with a default of course.
First, create different CSS files for each theme, e.g.
default_red.css
default_blue.css
default_yellow.css
Next, in html/header.php look for where default.css is currently included at line 12:
<link media='all' href='<?php print $config_baseHREF; ?>default.css' type='text/css' rel='stylesheet' />
...and REPLACE that with:
<?php
$themes = array("red","blue","yellow"); // first is default
$theme = (isset($_COOKIE["theme"])?$_COOKIE["theme"]:$themes[0]);
if (!in_array($theme,$themes)) $theme = $themes[0];
?>
<link media='all' href='<?php print $config_baseHREF; ?>default_<?php print $theme; ?>.css' type='text/css' rel='stylesheet' />
You'll also need a simple script to switch the theme, something like this:
theme.php
<?php
require("includes/common.php");
setcookie("theme",$_GET["theme"],strtotime("+1 year"),$config_baseHREF);
header("Location: ".$_GET["page"]);
exit();
?>
And finally, a form, maybe displayed on every page (e.g. in html/header.php) to switch theme:
<form method='get' action='<?php print $config_baseHREF; ?>theme.php'>
<input type='hidden' name='page' value='<?php print htmlentities($_SERVER["REQUEST_URI"],ENT_QUOTES,$config_charset); ?>' />
Switch Theme:
<select name='theme'>
<option value='red'>Red</option>
<option value='blue'>Blue</option>
<option value='yellow'>Yellow</option>
</select>
<input type='submit' value='Go' />
</form>
If you need more control than can be achieved via CSS the above can easily be extended to determine the name of the html/ folder from the cookie, let me know if you need any help with this...
Cheers,
David.
--
PriceTapestry.com