Results 1 to 6 of 6

Thread: Changing Theme

  1. #1
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Changing Theme

    I have many Themes in my Themes folder. What is the idea of changing theme through database. I mean is it possible to pickup one of theme from database?.

    Thank you in advance

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Well, the following code isn't exactly for a database but then I don't know why you'd want a database if you're going to be using stylesheets, why not just have them in a folder called "Themes" and then allow the user to select from one of them. Please try and explain how the database will be helpful in this situation.

    Anyway, here's a simple style changer:

    PHP Code:
    <?php
    if (isset($_GET['theme']))
        {
        
    $theme $_GET['theme'];
            switch (
    $theme)
            {
            case 
    1:
                
    $theme 1;
                break;
            case 
    2:
                
    $theme 2;
                break;
            case 
    3:
                
    $theme 3;
                break;
            case 
    4:
                
    $theme 4;
                break;
            default:
                
    $theme 1;
            }
            
    }
    ?>
    <html>
    <head>

    <link rel="stylesheet" type="text/css" href="theme<?php if(isset($theme)) { echo "$theme";} ?>.css"/>
    </head>
    <body>

    <form action="themes.php" method="get">
    <select name="theme">
    <option value="1">Theme 1</option>
    <option value="2">Theme 2</option>
    <option value="3">Theme 3</option>
    <option value="4">Theme 4</option>
    </select><p></p>
    <input type="submit" value="Select"/>
    </form>


    </body>
    </html>

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Better:
    Code:
    <?php
      session_start();
    
      $themes = array(
        'red' => 'Red',
        'greenish' => 'Green/Blue',
        'transparent' => 'Glass',
        'fish' => 'Sea Life',
        'grass' => 'Natural'
      );
    
      $defaultTheme = @$_POST['theme'];
      if (!isset($themes[$defaultTheme]))
        $defaultTheme = key($themes);
    
      $_SESSION['preferred_theme'] = $defaultTheme;
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
      <head>
        <link rel="stylesheet"
              type="text/css"
              href="<?php echo $defaultTheme; ?>">
      <?php foreach ($themes as $file => $title): ?>
        <link rel="alternate stylesheet"
              type="text/css"
              href="<?php echo $file; ?>.css"
              title="<?php echo $title; ?>">
      <?php endforeach; ?>
      </head>
      <body>
        <form action="<?php echo $_SERVER['REQUEST_URI']; ?>">
          <div>
            <select name="theme">
            <?php foreach ($themes as $file => $title): ?>
              <option value="<?php echo $file; ?>">
                <?php echo $title; ?>
              </option>
            <?php endforeach; ?>
            </select>
    
            <input type="submit" value="Select">
          </div>
        </form>
      </body>
    </html>
    Schmoopy, watch that pseudo-XHTML.
    Last edited by Twey; 01-24-2009 at 10:16 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    You mean the /> at the end of tags?

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes. In HTML, that technically ought to leave > characters scattered all over your page.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you so much friends for your help
    you are No. 1

Bookmarks

Posting Permissions

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