Llamasery.com Home  
 
Server-side Starter Tutorial: Themes and Skins - Part 2 of 7
Alfie the alpha_geek: Llamasery guru-in-waiting Tutorials Purpose

Starter Tutorials

Tell-a-Friend
Tell-a-Friend +
The 'Contact Form'
php Includes
Simple Themes
MySQL database 101
Comments System
Text Files

Intermediate Material

Articles/Tutorials

Skinning it - the start

First, we need something our site visitors can click to choose their theme. Somewhere on each page we need code like this:

<a href="settheme.php?newtheme=1">hot</a>
<a href="settheme.php?newtheme=2">cold</a>

That code causes the selected value of the theme (newtheme) to be passed to a php script for further handling. In the sample code above, clicking the 'hot' link passes the value 1 for newtheme to the file settheme.php. And the settheme.php file creates a cookie (that's how your visitor will 'remember' their theme for the next visit).

That code could be added as straight html to each of your pages .... but one day, you'll want to add another theme. So, save that code as links.php and we'll include it in every page. If you ever need another theme, edit one file not hundreds!

And the settheme.php file is just as simple. It uses the php function setcookie() - which, unsurprisingly, sets a cookie:

<?
// this cookie should last for ten years!!
setcookie("theme",$newtheme,(time() + (3600 * 24 * 365 * 10)),"/");
// and back to whence we came
header("Location: $HTTP_REFERER");
?>

So far, so good

Those were the easy bits, but next we need to do something with that cookie. And what we really want to do is read that cookie and then have a script that changes some variable(s) based on the cookied value of the $theme variable.

«  previous  |  next  »