Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
The non-plugin style switcher, version 2.0
Some of you may recall the non-plugin style switcher I released once upon a time. Perhaps you even have fond memories of trying to get it working on your site.
Well, now you get to start all over again, because version 2 is live.
This version has basically nothing in common with the previous one, which consisted of a few lines of PHP dashed together one night when I decided I wanted a style switcher. Version 2.0 is built to be much more flexible, and allows you to set and track as many different style variables as possible, and will (hopefully) be the foundation of a later version which partially integrates into TXP (jonhicks: I haven’t forgotten about you!).
The initial setup is the same as before, so you’ll need to replace your usual stylesheet link with a link to styles.php. You’ll also want to either name your default stylesheet default.css
or edit the script, and set the correct domain in the script. You can still, at your option, have a file called global.css
which will always be included, no matter what.
The switching mechanism is completely different, though; where previously you could only set one stylesheet to be used, and it was with a link of the form styles.php?style=foo
, now things are a bit more complicated. For one thing, to switch styles you’ll need to begin with set_style=1
. For another, you can pretty much name your styles any way you like, as long as they all start with style_
. The script will read through each style you set in the URL, set a corresponding cookie, and then on subsequent page visits serve the appropriate stylesheet.
Example
Suppose you want to let users switch to an alternative red color scheme, and/or switch to a larger base font size as well. Previously you would have needed four separate stylesheets (one for each of the possible combinations of color and font size), but now you only need two. Let’s suppose that your red color scheme is in a stylesheet called color_scheme_red.css
and your larger font size setting is in a stylesheet called font_size_large.css
. To offer a link to change to the red color scheme, you could do this:
<a href="styles.php?set_style=1&amp;style_color_scheme=red">Click for red color scheme</a>
And to offer a link to change to the larger font size:
<a href="/styles.php?set_style=1&amp;style_font_size=large">Click for larger font size</a>
To do both with one link:
<a href="styles.php?set_style=1&amp;style_color_scheme=red&amp;style_font_size=large">Click for red color scheme and larger font size</a>
And if you want to offer the option to unset a style, you can now use the argument clear_style
to do so; for example, to unset the font size in that last link:
<a href="styles.php?clear_style=style_font_size">Click to restore default font size</a>
You can use clear_style=all
to unset all styles with one click (thus restoring the defaults for everything).
If all of that sounds good, download the script and go to town. You may need to reorganize your CSS (or use a bit of planning when laying out CSS for a new site) in order to take full advantage of this, but I think the flexibility it provides is worth it.
Comments and suggestions are welcome, as are bug reports; I’ve done some testing and not run into any serious problems, but I also haven’t had time to put this into production use yet. Feel free to comment here or on my weblog entry for this.
Last edited by ubernostrum (2005-05-11 19:39:41)
You cooin’ with my bird?
Offline
Re: The non-plugin style switcher, version 2.0
I want this bad I couldn’t get the otherone working on a third style for some reason, But the link is dead 8(
EDIT: <a href=“http://www.shtuff.us/files/switcherv2.zip”>Download Here</a>
Last edited by soulship (2005-05-11 14:26:27)
Offline
Re: The non-plugin style switcher, version 2.0
Sorry about the typo in the download link, I should really avoid posting this stuff when I haven’t had much sleep.
You cooin’ with my bird?
Offline
Re: The non-plugin style switcher, version 2.0
Let me get this right…..
So I have a default style say default.css that I want as the main style. Then I have sytylered.css, styleblue.css, styleorange and stylegreen.css. I change the styles.php from include_css(‘default’); to include_css(‘stylered’); and upload it to the server root. Then I upload the other styles to the root and make my links like this:
<code><a href=”/styles.php?set_style=1;style_stylegreen”></code> <code><a href=”/styles.php?set_style=1;style_styleblue”></code> <code><a href=”/styles.php?set_style=1;style_styleorange”></code>Is this right?
Offline
Re: The non-plugin style switcher, version 2.0
Well, if your default style is called default.css
then you don’t want to change the include_css('default')
line; if you do you’ll change the stylesheet which is served as the default.
The links, though, are a problem. Try something like
<a href="/styles.php?set_style=1;style_color=stylered">
You need to have the actual styles in the form of style_name=value
in the URL.
Last edited by ubernostrum (2005-05-11 21:41:11)
You cooin’ with my bird?
Offline
#6 2005-10-29 18:52:49
- jessejericho
- Member
- Registered: 2005-10-29
- Posts: 25
Re: The non-plugin style switcher, version 2.0
I’m sorry for the super-noob question, but where do I tell the script where my css files are located? Or are the css files created in txp? I’m confused :(
Offline