WordPress.org

Forums

Alex's Style Switcher (9 posts)

  1. Anonymous
    Unregistered
    Posted 10 years ago #

    Hi,
    I have just been playing with Alex's Style Switcher and was wondering if there is a way to get it to work when the main index page is not in the WP directory.
    Currently my index page resides at http:.//www.acook.co.uk and the WP install is under a seperate directory /wp/.
    Having installed the plugin and initialised it with the supplied example styles, the links to switch styles tried to access http://www.acook.co.uk/wp/index.php..... which obviously did not work. I have looked at the code but my PHP is not good. I did try altering the calls for SiteURL, even hard coding my blog URL in but this seemed to make no difference. At the moment the plugin is deactivated so if you visit the site you won't be able to see the problem.
    I could move the wp install to root but I'd rather keep it the way I have it as I like a tidy root directory..

  2. Anonymous
    Unregistered
    Posted 10 years ago #

    Actually just implemented a javascript style switcher which does the job nicely....

  3. Sphyr
    Member
    Posted 10 years ago #

    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"]) &amp;&amp; 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) &amp;&amp; file_exists($path.$file.'/style.css') &amp;&amp; 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"]) &amp;&amp; $_COOKIE["wpstyle"] == $style) {
    $ss .= '

  4. '.$display.'
  5. '."\n";
    }
    else {
    $ss .= '

  6. .get_settings('home').'/'.get_settings('blogfilename')
    .'?wpstyle='.urlencode($style).'">'
    .$display.'
  7. '."\n";
    }
    }
    $ss .= ' ';
    }
    if ($in_list == 1) {
    $ss = '<li id="style">Style:'.$ss.' ';
    }
    echo $ss;
    }
    wp_style_cookie();
    ?>

  • Anonymous
    Unregistered
    Posted 10 years ago #

    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

  • Anonymous
    Unregistered
    Posted 10 years ago #

    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 :-)

  • Sphyr
    Member
    Posted 10 years ago #

    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. :)

  • gregsbaby64
    Member
    Posted 10 years ago #

    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 :)

  • ckronengold
    Member
    Posted 10 years ago #

    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

  • Mark (podz)
    Support Maven
    Posted 10 years ago #

    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>

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags

    No tags yet.