Theme Switcher (on website)

Discussion in 'Web Design & Coding' started by the_music_man, Jul 22, 2004.

  1. the_music_man

    the_music_man aka prodj88 =P

    Messages:
    2,401
    Location:
    USA
    Hi i was wondering if anyone could tell me how i can get a theme switcher for my site? all i want to do is let the users have the option to change the CSS background to black, blue, or red. its suppose to be a php code but i can't find it.
     
  2. Xie

    Xie - geek - Subscribed User Folding Team

    Messages:
    5,275
    Location:
    NY, USA
    I'm guessing your using some kinda of CMS? If so check there site for themes perhaps. :)
     
  3. the_music_man

    the_music_man aka prodj88 =P

    Messages:
    2,401
    Location:
    USA
  4. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    CMS is an acronym for Content Management System
     
  5. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    They way i do it is when you select your theme from the drop down box and press submit, it sets a cookies and refreshes the page, then at the top of the page checks the cookie and loads the corresponding CSS file.
     
  6. the_music_man

    the_music_man aka prodj88 =P

    Messages:
    2,401
    Location:
    USA
    ...i have no idea how to set cookies... isn't there just a php code u can use?
     
  7. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    yes, its all done in php, but theres no magical command "set_theme(blue)" or anything
    you have to build up the code

    setting cookies in php is easy
    Code:
    setcookie("NamOfCookie","value");
    and to retrieve
    Code:
    $variablename=$_COOKIE["NamOfCookie"]
     
  8. the_music_man

    the_music_man aka prodj88 =P

    Messages:
    2,401
    Location:
    USA
    i still don't understand how to do it...where would i put the CSS filename??? are CSS files the same as cookies?? and what would be the value
     
  9. the_music_man

    the_music_man aka prodj88 =P

    Messages:
    2,401
    Location:
    USA
    ok i found a good site but it doesn't work but i know its probably something i am doing wrong.
    http://www.alistapart.com/articles/phpswitch/
    when i click the link to change it it just takes me back to the homepage... any help?
     
  10. ~bk

    ~bk I Political User

    Messages:
    3,768
    Location:
    Canada
    CSS files are not the same as cookies.
     
  11. the_music_man

    the_music_man aka prodj88 =P

    Messages:
    2,401
    Location:
    USA
    yeah i know i just wanted to make sure. khaymans way seems harder than the tutorial
     
  12. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    Its the same way. They just spell it out simpler
     
  13. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
  14. the_music_man

    the_music_man aka prodj88 =P

    Messages:
    2,401
    Location:
    USA
    thanks i'll try it out and let you know how it works!!
     
  15. the_music_man

    the_music_man aka prodj88 =P

    Messages:
    2,401
    Location:
    USA
    im having problems on waht to put for the setcookie.php and style.php......i really don't know what to put in certain spots. i don't hvae a dark.css and i want to use my green.css and blue.css and default (tutlewax88.css)
     
  16. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
    Cahnge the code to match your Stylnames and css files.

    Code:
    <form action="style.php" method="post"><div>
    <span class="underline">Stylesheet:</span>
    <select name="style">
      <option value ="default">Default</option>
      <option value ="green">Green</option>
      <option value ="blue">Blue</option>
    </select>
    <br />
    <input type="submit" value="click to submit" /></div>
    </form>
    style.php

    PHP:
    <?php
      
    if ($_POST["style"]=="green")
        {
          
    setcookie("style""green"time()+2592000"/");
        }
      elseif (
    $_POST["style"]=="blue")
        {
          
    setcookie("style""blue"time()+2592000"/");
        }
      else
        {
          
    setcookie("style"""time()+2592000"/");
        }
    ?>
    <html>
    <head>
    <meta http-equiv=refresh content="0; URL=index.php" />
    <body>
    <h3>Applying theme</h3>
    <a href="index.php">Click here if you aren't redirected</a>
    </body>
    </html>
    setcookie.php

    PHP:
    <?php
      
    switch ($_COOKIE["style"])
      {
      case 
    green:
      echo (
    '<link rel="stylesheet" type="text/css" href="css/green.css" />');
      break;
      case 
    blue:
      echo (
    '<link rel="stylesheet" type="text/css" href="css/blue.css" />');
      break;
      default:
      echo (
    '<link rel="stylesheet" type="text/css" href="css/tutlewax88.css" />');  
      }
    ?> 
     
  17. Kush

    Kush High On Life!

    Messages:
    4,590
    Location:
    Montreal, Quebec
    off topic, but hey ~bk when i was in lebanon we saw the slr in downtown, it was a prince from UAE, and another prince had the new audi a8 all chromed out! talk about changing colors in cms LOL!
     
  18. the_music_man

    the_music_man aka prodj88 =P

    Messages:
    2,401
    Location:
    USA
    yeah i have the style.php and setcookie.php but it still doesn't work? and btw did u get my pm
     
  19. ~bk

    ~bk I Political User

    Messages:
    3,768
    Location:
    Canada
    [​IMG] [​IMG]