...

View Full Version : How to make a style switcher.......



SDP2006
10-22-2003, 08:55 PM
This question has been asked very often so here is a tutorial.....

Okay, first off you're going to need a drop down menu box....


<form action="switchstyle.php" method="POST">
<select name="styles">
<option value="Blue">Blue</option>
<option value="Green">Green</option>
<option value="Red">Red</option>
</select>
<input type="submit" value="Go!">
</form>
Of course you can add as many styles as you would like, but I'm just doing Blue, Green, and Red for examples...

Now for switchstyle.php

<?php
/*What this does is sets a cookie with the value that the select box had when Go! was clicked and redirects the browser to back to your homepage where the stylesheet will be change*/
Header("Location: http://www.yourdomain.com/index.php");
$value = $_POST['styles'];
setcookie("stylesheet",$value,time()+60*60*24*30);
?>

No for your page where the style is going to be changed...


<?php
/*This checks to see if a cookie has been set (from switchstyle.php) and if it is, it sets the variable $sheet to what the value of the cookie is.css*/
if(isset($_COOKIE['stylesheet'])){
$sheet = $_COOKIE['stylesheet'].'.css';
}else{
$sheet = "Blue.css";
}
echo '<link rel="stylesheet" type="text/css" href="'.$sheet.'">';
/*Here Blue.css is the default style sheet. If another isset, then that will be the stylesheet*/
?>


Now you will obviously have to make the stylesheets yourself. You can change the values on the drop down box. For instance, if you have Green, you need to have a Green.css in this same directory.

Hope this helps....

Any questions or comments, post back here.....

<stickify>??

SDP2006
10-23-2003, 01:19 AM
I can feel some criticism coming on from Spookster & Nightfire....:p

Nightfire
10-23-2003, 02:28 PM
I ain't sayin a word :D ALthough I was typing something yesterday and thought "bah, forget it" :D lol

Erich
11-05-2003, 10:53 PM
Is there an easy way to include an SSI into the style switch? Like if i wanted to change the header or sidebar to match the new style set?

Also, how could I carry this over to every page on the site, or is that implied with the script?

Nightfire
11-06-2003, 12:08 AM
I doubt you can do this with SSI.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum