Style Changer

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

On a few sites (like for example Suzanne's) there is an option of changing the style sheet that you are currently using, no doubt this can be done with PHP but how?

Busy's picture

He has: 6,151 posts

Joined: May 2001

several ways to do it, I think the most common is like:

if option a, use stylesheet 1
elseif option b, use stylesheet 2
else use default

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

If you have a member base, then store the user's choice in a db. If not, you could just pass data on by querystring, and on each page do what Busy says. Could even store the style choice in a cookie or in a session.

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

Yes, I thought it would be something like that, but the real question is, how is it done? or what is one (the easiest and best) way to do it?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

SET THE STYLESHEET:

   
<style type="text/css">
    @import "/styles/advanced.css";
    @import "/styles/<?php echo (!$sitestyle)?'default':$sitestyle ?>.css";   </style>
'

SAMPLE LINK:

<li id="websafe"><a href="/scripts/switchcss.php?set=websafe">Websafe Palette</a></li>
'

THE SCRIPT:

The script takes the variable and sets it as a cookie on the user's computer.

http://www.google.com/search?q=php+style+switcher

There are many open source php style switchers out there, read through the ALA article's comments for some insight into why one is better than another.

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

Thanks Suzanne Laughing out loud I'm going to try it out soon on my reading site Laughing out loud

DC_Sara's picture

She has: 392 posts

Joined: Jan 2002

I used skins and that seems to work the best for me. It sets a cookie and the person reading the site has an option of choosing the one that they want from a basic index page of the skins directory.

You can see it at work here: simplysara.com/blog/ and I have a tutorial here: graphics-by-sara.com under tutorials, under PHP Smiling

~*Sara*~

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

Thanks for the help everyone, finally finished a style Laughing out loud found here:
http://chengeu.krayup.com/reading/index.php?page=body&maincss=blue

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Now make them a cookie so they stay! Wink

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

GG -- skins are the same thing as style switchers, only you have to create entire templates of html as well as just the stylesheet. When using valid markup and css positioning, you can use stylesheets to do everything and store the preference in a cookie.

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

i don't know how to set cookies :S

He has: 296 posts

Joined: May 2002

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

The alistapart article and the forums explain how to set cookies, hon.

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

cool, thanks for the links, i'll have a look sometime this week Smiling

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.