The Flash and PHP Bible has been released! The book can be found on Amazon or wherever fine books are sold in your area. This book explains the process of working with PHP in Flash, while creating real world examples that you can actually learn something from.
The Flash and PHP Bible has a dedicated forum for support and comments.
How to write a script that will allow you to easily load another stylesheet.
Here is the code to set the style
<?php
if(!empty( $_GET['theme'] ))
{
$style = $_GET['theme'];
switch( $style )
{
case 'style1':
$style = 'style1';
break;
case 'style2':
$style = 'style2';
break;
case 'style3':
$style = 'style3';
break;
}
}
print "";
?>
if(!empty( $_GET['theme'] ))
{
This is saying if the "theme" variable is not empty than continue with the script. It reads the "theme" variable and stores the value.
$style = $_GET['theme'];
Set the value of "theme" into the "$style" variable. This can be left as a get variable, but it is easier to use a smaller, more clear variable.
switch( $style )
{
case 'style1':
$style = 'style1';
break;
case 'style2':
$style = 'style2';
break;
case 'style3':
$style = 'style3';
break;
}
This next piece of code is a "switch" statement. The "case" part is the string it looks for. For instance if $style had a value of "style3" than the script would load the 3rd stylesheet. The "break" says if the value of "$style" is found then jump out of the switch.
}
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"
This is a PHP "print" or "echo". It is outputting the first part of the code to load a stylesheet into a site.
}
" . ( ( !$style ) ? 'main' : $style ) . ".css\" />";
This is a tertiary operator: 1?2:3, which means "if 1 is true, then 2, else 3". This means if the "$style" variable is not filled then load "main.css". Or if it is filled, load the selected style.
That is all there is to writing a style switcher in PHP
|
Ali Thu Sep 1, 2005 4:26 am
W00t, this is a pretty useful script and I think its just what I've been looking for.
|
|
mkeefe Mon Sep 5, 2005 1:39 am
Glad to hear that you liked and found use for this article. It is always nice to hear from people that appreciate your work. Keep in mind if you have an article idea you can simply request it. :)
|
|
Haol Thu Oct 27, 2005 4:55 am
oooo, this is kl, very helpful i have laods of ideas that i can use this code for.
|
|
Jhecht Sat Jul 14, 2007 1:49 am
I used to use a javascript method to this... i believe all i did was find a link tag, then i'd check to see if the relationship attribute was "stylesheet", if it was, i'd update it with the separate stylesheet being clicked on. It used to work, not sure about it now.
|
|
anonymous Thu Feb 28, 2008 11:39 pm
coded a full fledged theme engine in php.
http://tinyurl.com/yrb8yn (tinyurl link, the link is a bit long) bye... P.S. the demo may not work sometimes |
|
gaurav_m Thu May 15, 2008 12:12 am
Nice !!!
like it |
|
Busby SEO Challenge Sun Aug 3, 2008 12:33 am
Wow.. This is great! You can use this for creating different styles in WordPress.
|
©2004 - 2008 scriptplayground | Privacy Policy | Legal
Validate Site: XHTML CSS | Designed by: Matthew Keefe of mkeefeDESIGN