Help - Search - Members - Calendar
Full Version: stylesheet switcher off main index
Movable Type Community Forum > Additional Resources > Tips and Tricks
halbarad
Greetings,

The last few days I've been working on a stylesheet switcher, using the tutorial found here:

http://www.aspyre.net/aj/switchtut.html

I looked at several others, but this was the most straightforward approach . And it works on my site, at least for the main index.

But:when I copy the replacement css refer line from my new main index, and place it into my individual archive template...well, it doesn't work. I tried several times, and attempted rebuilding things in different orders: rebuild entire site, rebuild indexes then individual archives, etc.

Any ideas? (I should note that my primary css is used site-wide, and the only change in the new stylesheet is tinkering with font sizes. So it isn't a matter of a different css being default in the main index and for archives.)
halbarad
btw, the site is question is

http://www.andunie.net

You can see the stylesheet switcher in action on the front page. The stylesheet switcher icons are also on the archive pages for individual posts, but I took out the php refer in the template header for that archive (it wasn't working, and leaving the replacement line in made the individual entries look like garbage).

So the question remains: why should the line

CODE
<link rel="stylesheet" type="text/css" media="screen" title="User Defined Style" href="<?php echo (!$styleselect)?'styles-site':$styleselect ?>.css" />


work when in the header of the main index, but not in the header for individual archive pages?

thanks again,

--Anthony
TweezerMan
Your stylesheet switcher has a bit of a flaw in it, because the instructions you followed have the same flaw.
CODE
<a href="./switcher.php?set=styles-site" title="Default font size">
<a href="./switcher.php?set=styles-site_plus" title="Large font size">

Because the href starts with "./", the links to switcher.php are relative to the location of the page that the link is on.

On your main weblog page (http://www.andunie.net/), the full link to the stylesheet switcher ends up being:
CODE
http://www.andunie.net/switcher.php?set=styles-site

...which works just fine, because switcher.php is in the root directory of your domain.

On an individual archive page (such as http://www.andunie.net/mt-archives/000274.php), the full link to the stylesheet switcher ends up being:
CODE
http://www.andunie.net/mt-archives/switcher.php?set=styles-site

...which does *not* work, because switcher.php is not in the /mt-archives directory of your weblog.

There's at least a few ways to deal with this problem. Since your weblog is at the root of your domain, the easiest solution is to remove the "." from the beginning of the href links, so they will be relative to the domain root instead of the page's URL:
CODE
<a href="/switcher.php?set=styles-site" title="Default font size">
<a href="/switcher.php?set=styles-site_plus" title="Large font size">

A more general solution would be to use the MTBlogRelativeURL tag:
CODE
<a href="<$MTBlogRelativeURL$>switcher.php?set=styles-site" title="Default font size">
<a href="<$MTBlogRelativeURL$>switcher.php?set=styles-site_plus" title="Large font size">

Side note: Your individual archive template does not have an alternate stylesheet 'link' tag like your main index template does. Not a big deal, but I thought I'd point it out while I was looking.

Hope this helps...
halbarad
David,

It turns out that the problem you described was indeed a problem--just one I hadn't gotten to yet.

The more immediate issue was that the stylesheets weren't being called correctly. Instead of

CODE
<link rel="stylesheet" type="text/css" media="screen" title="User Defined Style" href="<?php echo (!$styleselect)?'styles-site':$styleselect ?>.css" />


I needed

CODE
<link rel="stylesheet" type="text/css" media="screen" title="User Defined Style" href="<$MTBlogURL$><?php echo (!$styleselect)?'styles-site':$styleselect ?>.css" />


Your suggestions got me going. Many thanks.

--Anthony
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.