Stylesheet Chooser Version 0.2 Comments RSS feed

I had tried for a while to find a way to allow users to choose their favorite theme for this website. I decided to do it as a Wordpress plugin, which I offer today for other Wordpress users.

Installing it is quite simple: Download, rename to stylesheet_chooser.php, upload it to your wp-contents/plugins directory and activate it from the admin interface.

To define which stylesheets to use (no, it’s not automatic…), you have to define an array called $styles, before you call any of the other functions.You can do it like this, for example :

$styles=array("styles/default","styles/no-style")

if your stylesheets are in the styles directory. Omit the ‘.css’ part. The first one in the list will be used as your default style. The plugin will automatically select the last part of the path (in this case new, default and no-style) and use them as the text in the selection box.
The optional parameter – for example style_link(false) – can be set to ‘true’ (default) if you want to @import the style sheets (ignored by NS4), or to ‘false’ to get this kind of links: <link rel=”stylesheet” title=”….> for the current chosen style sheet and like this:<link rel=”alternate stylesheet” title=”….> for the other(s).

style_chooser() will insert the form that is used to select the stylesheet. Place it wherever you want, in your sidebar for example.

In version 0.23+, it is possible to have a short comment appear below the selection dropdown. For this, the only thing you have to do is insert it in your stylesheets like this:

/*
Comment: Write your comment here.
*/

And that’s it, now each stylesheet has it’s own “introduction text”.

Now that you know all this, you can :

  • Download
  • write a comment,
  • or Contact me in case you have problems
Liked it? Share it!
  • del.icio.us
  • Facebook
  • Google
  • TwitThis
  • StumbleUpon

28 Responses to “Stylesheet Chooser Version 0.2”

  1. [...] r slvShowNewIndicator(1094170038); Filed under: WordPress Plugins|Google it! This Wordpress plugin allows users to change stylesheets. [...]

  2. Frank says:

    The style chooser only works when you have cookies enabled. I always have cookies disabled in Firefox, with exceptions for a couple of sites. I don’t know if there is a workaround possible so this works without the use of cookies, but that might be preferable to this solution if it works in all situations.

  3. Andr? says:

    Dear Jonathan,
    why does the plugin created this stylesheet-tag at the end link rel=”alternate stylesheet”type=”text/css” media=”screen” title=”" href=”http://www.jfoucher.marinetechs.com/css”

  4. Nik says:

    show_chooser() ?? When you’ve got style_link(), it’d be more understandable to choose style_chooser() as function name. Makes it more easy to see what functions come from what plugin

  5. Michiel says:

    Hi, the download does not work, it is redirected to http://www.jfoucher.marinetechs.com/2004/09/02/stylesheet-chooser/

  6. Jonathan says:

    Sorry to all the recents commenters. I had some database problems and lost some of the newest comments. I even lost one post that wasn’t backed up, but got it back from Google’s cached version. Thanks !

    Thanks to Francesco too, for correcting that bug.

  7. Antti Lev?saari says:

    Hi!

    I have a problem with this plugin. It displays the default stylesheet but I’m not able to change the stylesheet to another. It just gives me a 404 error page, what’s wrong?

  8. francesco says:

    same problem here.

  9. francesco says:

    i’ve fixed it this way:
    around line 156 in the plugin you find the form. action is srt to “/”, replace it with “< ?php echo $_SERVER["REQUEST_URI"]; ?>“

  10. Jonathan says:

    Ok, I managed to restore the comments from the notifications I received by email, but I don’t know if you were subscribed to comments. If you were, you aren’t anymore, I didn’t want to force this on anybody…

  11. francesco says:

    now i have another small problem: i have to change style twice in order to see it applied. the weird thing is that on my server at home i just need to switch once, while on my provider’s one i have to do it twice. Maybe an issue with different versions of php? i haven’t had the time to check the code again to see if i can fix this. anyone else had the same problem?

  12. Erwin Panen says:

    Hello,

    I’m not very familiar with WordPress or PHP. Where do I have to create the array you mention? ($styles=array(“styles/new”,”styles/default”,”styles/no-style”))
    Could you please elaborate a little on this?

    Merci beaucoup,

    Erwin

  13. [...] changes this may or may not happen, but it s pretty cool to think about, eh? Jonathan Foucher – Salamba ? Stylesheet Chooser Version 0.2 –>
    –> [...]

  14. [...] As a self-prescribed stress-relieving treatment, I have installed Jonathan Foucher s style sheet chooser plugin for WordPress, so now you can choose your favorite style to look a [...]

  15. Margaret says:

    I’m getting the following error:

    Fatal error: Call to undefined function: lp() in /home/margaret/public_html/wp-content/plugins/stylesheet_chooser.php on line 184

    You can see it in action. I, too, am not versed in php, so I’m just sort of muddling my way through.

  16. Nifty new styleswitcher
    As a self-prescribed stress-relieving treatment, I have installed Jonathan Foucher’s style sheet chooser plugin for WordPress, so now you can choose your favorite style to look at the page. The new style is called “Whistler” because it’s based on …

  17. Joseph says:

    I have a problem similar to the one Antti Lev?saari experienced:

    1. I put the stylesheet_chooser.php file in my wp-content/plugins directory and it is Activated on my WordPress Plugins page.
    2. my stylesheets are in the /styles folder (they are named no-style.css, default.css and new.css).
    3. I INSERT style_link(false) between the Head tags of my Index.php page.
    4. I INSERT style_chooser() in the Body of my page.

    Yet the website shows all three CSS styles but only loads the one listed first. Have I missed a step?

    here’s the example…
    http://www.strangeisle.com/

    Thank you.

  18. [...] 220;Simple Sky, though I m working on some changes. Jonathan Foucher s Style Sheet Chooser lets users choose the css they prefer. So hereR [...]

  19. Jonathan says:

    It is possible to use sessions instead of cookies, but I have trouble understanding their behaviour.
    I will try to find a way, though. Keep in touch if you’re interested in the cookie-free version.

  20. Jonathan says:

    That was a little bug, thanks for pointing it out.

    It’s fixed in the new version.

  21. Antti Lev?saari says:

    And it doesn’t insert the alternative stylesheet links (

  22. Jonathan says:

    Yes! of course!

    Francesco, a big thank you to you!

  23. Antti Lev?saari says:

    Whippee!

    Thank you, Jonathan, for this great plugin and thank you, Francesco, for this great fix!

  24. Jonathan says:

    In fact, using $_SERVER['REQUEST_URI'] didn’t work at all for me, so I used get_bloginfo(‘url’), which gives the correct url in all cases.

  25. Jonathan says:

    Anywhere above the style_link() function call is fine.

    If you have to css file named wp-layout.css and wp-layout2.css in the same directory as your index.php file, the array definition would look like this :

    $styles=array(“wp-layout”,”wp-layout2″);

    Hope this helps.

  26. Jonathan says:

    Yeah, sorry about that, my mistake. Should be solved now if you download it again. But I see you got your problem solved. Nice looking alternative style, BTW.

Leave a comment

If you register, these will be filled automatically