Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to make a style switcher.......

    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....
    Code:
    <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 Code:
    <?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 Code:
    <?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>??
    Last edited by SDP2006; 10-22-2003 at 09:29 PM.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can feel some criticism coming on from Spookster & Nightfire....
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I ain't sayin a word ALthough I was typing something yesterday and thought "bah, forget it" lol

  • #4
    New Coder
    Join Date
    Mar 2003
    Location
    NYC
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    ~ Erich w/ an h

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I doubt you can do this with SSI.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •