Thread Starter
Anonymous
Actually just implemented a javascript style switcher which does the job nicely….
I took a comment from Beel several months ago and now I use this for my style switcher plugin. Basically it involved changing “home” to “siteurl” in several places. I’m posting the whole thing in case somebody sees an error, but it’s been working fine for me on WordPress 1.2 for several months now.
<?php
// WP Style Switcher
// version 1.2, 2004-03-03
//
// copyright 2004 Alex King
// http://www.alexking.org/software/wordpress/
/*
Plugin Name: WP Style Switcher
Plugin URI: http://www.alexking.org/software/wordpress/
Description: A CSS Style Switcher for WordPress.
Author: Alex King
Author URI: http://www.alexking.org/
*/
// change this to the name of default style you want to use
$wp_style_default = 'Blue Swirly';
function wp_style_cookie($default = "") {
global $wp_style_default;
if (empty($default)) {
$default = $wp_style_default;
}
$expire = time() + 30000000;
$urlinfo = parse_url(get_settings('home'));
$path = $urlinfo['path'];
$domain = $urlinfo['host'];
if (!empty($_GET["wpstyle"])) {
setcookie("wpstyle"
,stripslashes($_GET["wpstyle"])
,$expire
,$path
,$domain
);
header("Location: ".get_settings('home'));
}
else if (empty($_COOKIE["wpstyle"])) {
setcookie("wpstyle"
,$default
,$expire
,$path
,$domain
);
}
}
function wp_stylesheet($default = "") {
global $wp_style_default;
if (empty($default)) {
$default = $wp_style_default;
}
if (!empty($_COOKIE["wpstyle"]) && file_exists('wordpress/wp-style/'.$_COOKIE["wpstyle"].'/style.css')) {
$style = $_COOKIE["wpstyle"];
}
else {
$style = $default;
}
echo get_settings('siteurl').'/wp-style/'.$style.'/style.css';
}
function wp_style_switcher($in_list = 1, $type = "text", $preview = 0) {
$styles = array();
$path = "wordpress/wp-style/";
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if (is_dir($path.$file) && file_exists($path.$file.'/style.css') && substr($file, 0, 1) != '.') {
$styles[] = $file;
}
}
}
closedir($handle);
if (count($styles) > 0) {
asort($styles);
reset($styles);
$ss = '<ul id="styleswitcher">'."\n";
foreach ($styles as $style) {
switch ($type) {
case "sample":
if (file_exists('wp-style/'.$style.'/sample.gif')) {
$sample = get_settings('siteurl').'/wp-style/'.$style.'/sample.gif';
}
else {
$sample = get_settings('siteurl').'/wp-style/sample.gif';
}
$display = '<img src="'.$sample.'" alt="'
.htmlspecialchars($style).'" title="Use this Style" />';
break;
default:
$display = htmlspecialchars($style);
break;
}
if ($preview != 0) {
if (file_exists('wp-style/'.$style.'/screenshot.gif')) {
$display .= '
.'/wp-style/'.$style.'/screenshot.gif">Screenshot';
}
}
if (!empty($_COOKIE["wpstyle"]) && $_COOKIE["wpstyle"] == $style) {
$ss .= '
- '.$display.'
'."\n";
}
else {
$ss .= '
.get_settings('home').'/'.get_settings('blogfilename')
.'?wpstyle='.urlencode($style).'">'
.$display.'
'."\n";
}
}
$ss .= '
';
}
if ($in_list == 1) {
$ss = '<li id="style">Style:'.$ss.'
';
}
echo $ss;
}
wp_style_cookie();
?>
Thread Starter
Anonymous
Ah.. I figured something must replace ‘SiteURL’ but didn’t know what.
Thanks for that. I’ll give it a go next week sometime.
Rgds
Andy
Thread Starter
Anonymous
Actually just grabbed 10 minutes of peace at work to check it out.
One thing I’d add to the instructions is that any and all occurances of the ‘wp-styles/’ directory and ‘/wp-styles/’ directories must be updated to ‘yourwpdirectory/wp-styles/’ and ‘/yourwpdirectory/wp-styles/’. Obviously replacing yourwpdirectory with the name of whatever directory you have WP installed in.
Other than that, it seems to work fine.
Nice one 🙂
I had forgotten what I did, it’s been too many months. I should have documented it, but I didn’t think I’d be sharing it since I’m not the author. 🙂
Is there a way to make the Style Switcher work for pages in other directories? I have just static pages and I would like to get the style switcher working on them as well.
Thanks,
Sara 🙂
I tried to deactivate the style switcher, but when I do, I get left with a totally blank page.
Can I take one of the styles from the wp-style folder and move it to main main WP folder, and rename it wp-layout.css?
I installed the WP 1.2 with all of Alex’s plugins already installed, mainly for the pictures upload feature. I’m wondering if I’m just not in over my head with all of this code.
http://www.theviewfrommysofa.com/wordpress
Yes.
So long as all the switcher code has gone, move the css and images and have this in index.php to call the correct code:
<style type="text/css" media="screen">
@import url( <?php echo get_settings('siteurl'); ?>/wp-layout.css );
</style>