Alright! For the long-awaited Skinning Tutorial!^^ Credits to my guardian angel, Maddy for the script. *hugs* I edited it to be more compatible with the latest versions of PHP.
<HTML> <head> <title>Site Name Here</title> <link rel="stylesheet" type="text/css" href="style1.css" /> </head> <body> <div align="center"> <center> <br> <table border="1" cellpadding="2" cellspacing="0" width="750"> <tr> <td colspan="3"> <img border="0" src="topbanner1.jpg" alt="Top Banner One" /> </td> </tr> <tr> <td valign="top" width="150" height="32"> <h1>Navigation</h1> : : <a href="links.php">Link Here</a><br> : : <a href="links.php">Link Here</a><br> : : <a href="links.php">Link Here</a><br> : : <a href="links.php">Link Here</a><br><br> </td> <td valign="top" width="600" height="32" > ////main content of your site here... </td> </table> </center> </div> </body> </html>
Take note of the bold characters for they indicate the elements that are to be distinct in each layout. For the top codes, since we’re using layout1, the elements are topbanner1.jpg and style1.css. In the same way, when you create the other two layouts, layout2 should have topbanner2.jpg and style2.css, while layout3 has topbanner3.jpg and style3.css.
Now let’s separate the codes of the first layout into three parts. The first part being:
<HTML> <head> <title>Site Name Here</title> <link rel="stylesheet" type="text/css" href="style1.css" /> </head> <body> <div align="center"> <center> <br> <table border="1" cellpadding="2" cellspacing="0" width="750"> <tr> <td colspan="3"> <img border="0" src="topbanner1.jpg" alt="Top Banner One" /> </td>
As you can see, the top code includes all the elements that are variable in between skinning, the top banner and the style sheet. Save this file as layout1.txt. Do the same with the other two layouts, saving the top codes as layout2.txt and layout3.txt respectively. This will be the last time you will have to handle the other two layouts. From here on out the rest of the skinning process can be achieved just by using the first layout since, other than the top banner and CSS, the three layouts are identical.
Now let’s move on to the next part of your code (still using layout1). This will create a file for all the "constants" of your site, meaning all the parts that will not change throughout your site. (See the tutorial on PHP Includes for more info).
<tr> <td valign="top" width="150" height="32"> <p>Choose a SKIN</p> <center> <a href="main.php?mode=style1">Layout 1 Title</a><br> <a href="main.php?mode=style2">Layout 2 Title</a><br> <a href="main.php?mode=style3">Layout 3 Title</a><br> <br><br> <h1>Navigation</h1> : : <a href="links.php">Link Here</a><br> : : <a href="links.php">Link Here</a><br> : : <a href="links.php">Link Here</a><br> : : <a href="links.php">Link Here</a><br><br> </td> <td valign="top" width="600" height="32" >
Now save this part of the code as links.php. As you can see it’s almost identical to the original code. I’ve added the text links in bold letters that will enable visitors to choose the skin they want. You can also use small screencaps of your layouts as links to skinning if you want, but please link them in the same way.
For the rest of the code…
<?php include "header.txt"; include "links.txt"; ?> ////main content of your site here... </td> </table> </center> </div> </body> </html>
Save this file as main.php. Notice we’ve added a PHP code up top that will call for the files header.txt and links.txt to be included? (See the PHP Includes tutorial on an in-depth explanation). This file will contain the main content of your index page and will be the format of your succeeding pages. For example, you want to create a new file, an “about me” page, so this is what you have to do:
<?php include "header.txt"; include "links.txt"; ?> <p>About Me</p> Likes: Chocolate<br> Dislikes: Arrogant people<br> More.... </td> </table> </center> </div> </body> </html>
Save that file as aboutme.php and link to it by editing links.txt . Make sure you save it with a .php extension, otherwise the PHP script wouldn’t work.
Now for the magic! ^^ Copy the following code and save it as header.txt.
<?php
session_start();
if(!isset($_GET['mode'])){
$_GET['mode']='default'; //set default sheet
}
switch($_GET['mode']){
case 'default':
if(empty($styled)){
include "layout1.txt";
}
elseif(!empty($styled)){
if($styled=="style1"){
include "layout1.txt";
}
if($styled=="style2"){
include "layout2.txt";
}
if($styled=="style3"){
include "layout3.txt";
}
}
break;
//====================================
case 'style1':
session_register("styled");
$styled="style1";
include "layout1.txt";
break;
//====================================
case 'style2':
session_register("styled");
$styled="style2";
include "layout2.txt";
break;
//====================================
case 'style3':
session_register("styled");
$styled="style3";
include "layout3.txt";
break;
//====================================
}
?>
And we’re done! Now you can start skinning your site. You can skin as many layouts as you want as long as you keep adding a new style and case in your header.txt. Also, make sure that the paths to your files are correct, especially in header.txt so it can switch to the right header when necessary. To be safe just put all your files in the same folder.
That’s all and have fun!^^


