Click to See Complete Forum and Search --> : Switching site templates w/ a script?
FooDang
08-31-2004, 12:39 AM
Hi, im making a website now thats going to have 2 layouts, red and blue, i am wondering if there is a script or something i can use to swap out the stylesheet and images used on the page...
http://www.juggalo-homies.com/hellspit/index.php
thats what the "red" layout will look like, and what i want to do is, switch the stylesheet and the images used such as the banner, nav, and table bgs.
thanks in advance for your help
Dark_Raver
08-31-2004, 12:57 AM
Here is an example of how someone does it with a style sheet.
http://www.blackviper.com/
you could have all the resources for the blue site in folder 'blue' and red in folder 'red'. then have php specify the folder to these at runtime based on session, get or post variable.
DR
CompGeek01
09-01-2004, 02:39 PM
If you are feeling adventerous and have access to the php configuration file (aka. owning your own server)...you can actually dynamically generate your .css files with php. It's an interesting effect that allows for numerous things such as user defined styles and random schemes.
Also, with PHP you can choose between 2 styles with an include:
<?
if ( site1 ) {
include( 'style1.css' );
}
else
{
include( 'style2.css' );
}
?>
Given you'll have to have a real if/then statement and styles that actually exsist, but it still creates a lot of cool effects.
FooDang
09-01-2004, 04:00 PM
how would i make a link to change it to style2.css?
Dark_Raver
09-01-2004, 08:44 PM
it depends how you want to do it. but a fairly easy way to do it is to use 'get' variables.
your link could look like this...
<a href='your_site.php?color=red'>See me in red</a>
<a href='your_site.php?color=blue'>See me in blue</a>
and in your page you could have...
$get_color = $_GET['color'];
if ( $get_color == "red" ) {
// show red
} else if ( $get_color == "blue" ) {
// show blue
}
downside of this method is that you would have to always show the '?color=red' part in the url.
to avoid this you could store the color value in a session variable and retrieve it from there on subsequent pages.
$_SESSION['color'] = $get_color; // to set the variable
$get_color = $_SESSION['color']; // to read the session variable into a local variable
a word of caution if you decide to use session variables. some servers will have the php set up in a way so you can use session variables without having to use the '$_SESSION' and will allow you to simply go '$color'.
there are other ways of doing this but, i think this is the simplest one. you might also consider using cookies instead of session variables. it takes more work to use cookies but they can be more permanent.
DR
SysOpt.com
Copyright Internet.com Inc. All Rights Reserved.