Page 1 of 1

Site skins - how to switch images

Posted: Sat Jan 25, 2003 9:17 am
by White_Coffee
Hi PHP gurus! A silly little newbie is waiting for the touch of your wisdom :lol:

I'm working on making my site skinnable. I do not mean something sofisticated, just different color schemes and matching images.
I've been searching a lot, found some nice scripts and tuts (e.g from A List Apart, Domesticat.net etc), made them work for me but run into a problem. All these scripts are only allow to switch CSS and/or page header/footer but I want to switch images for each skin, ALL images, including bullets, buttons etc. I know I could do it like that:

Code: Select all

<?php
switch ($theme)&#123;

case "green":
 
$stylesheet = "skins/green/style.css"; 
$logo = "<img src="skins/green/logo.gif" alt="" width="48" height="48" />"; 
$bullet = "<img src="skins/green/bullet.gif" alt="" width="7" height="7" />"; 
break; 
.....

?>
and so on.

but I'm terrified with the thought of listing all images for each skin this way 8O

What I want is to have it like they do in ready-made CMS:

Code: Select all

<img src="&#123;$skinpath&#125;/logo.gif" alt="" width="48" height="48" />


But since I'm new to PHP I have no clue how to implement that. So help, hints, links would be greatly appreciated. TIA

hmm

Posted: Sat Jan 25, 2003 10:53 am
by uberpolak
The closest thing I can think of to what you're trying to do would be storing the information from each theme in a database, you'd still have to use some sort of switch though...

Posted: Sat Jan 25, 2003 11:03 am
by jollyjumper
Hi white coffee,

I think you are allmost there with the code you posted.
If you replace all the words green with $theme then you don't have to have to use a switch. But this is only working when all the images which should be skinnable are the same size, I don't know if that's what you want, it is the case with the skinnable site I'm working on.

Below I posted your code with the adaptions I described above.

Hope it helps you.

Greetz Jolly.

Code: Select all

<?php 
$theme = "green"; //or any other skin color you have made.
$stylesheet = "skins/" . $theme . "/style.css"; 
$logo = "<img src="skins/" . $theme . "green/logo.gif" alt="" width="48" height="48" />"; 
$bullet = "<img src="skins/" . $theme . "/bullet.gif" alt="" width="7" height="7" />"; 
?>

Posted: Sat Jan 25, 2003 11:42 am
by White_Coffee
Thanx jollyjumper, will try to play around with your version of the code.
Yes, all my images are the same size, I just want blue bullets for blue skin, green for green etc.

As for the using database as uberpolak suggested, i'm still learning all this stuff so maybe later... I can't even figure out how to store theme info in a database :cry: I'm a webdesigner, not programmer... just trying to make my site better and learn PHP cuz I do like it. :)

Posted: Sat Jan 25, 2003 4:07 pm
by jollyjumper
You're welcome white coffee,

Another small tip to make your start with php easier, go to http://www.php.net, and download the latest manual in .chm format, at least if your platform is windows. It's an offline manual about all the functions in php with comments of other developers about how to use a particular function. Also it has a search function which helps a lot..

About the code I posted, it has a small error in it, in the image line I forgot to delete the word green, I guess you allready saw it, but I guess I'd just mention it.

Okay good luck with developing.

Greetz Jolly.