After being asked this question so many times, I finally made a tutorial for skinning your site with PHP. You need soem basic knowledge of PHP for skinning, please read the PHP includes tutorial if you dont know how to do that, before you start reading this one. Any questions regarding this tutorial should be asked here.
Make 2 or 3 layouts (as many skins as you want, you can add more later anytime you want) code them like you code every layout you make. Now, break the coding of each layout into 3 parts for skinning, just like you break them in 2 parts, header.php and footer.php, you now have to make another part and call it anything for now lets call it body.php this is the middle part, the part of coding which is NOT common for all pages, the main content part, that is, the part which has the main content of page. Remember from reading the PHP include tutorial, header.php is the part which is common in all pages, its the beginning of your layout coding, body.php will be the main content and footer.php will be the rest of part towards end of coding which is also common in all pages, it may include your navigation...and the copyright notice, or it may have only this </body> </html> This depends on te way you break the coding. My header.php have the beginning of my layout coding (including, the top image, the css file link, the beginning of tables or div position of my main content etc. The body.php for pages have the main content of that page, and my footer.php has the navigation, table closing tags, the copyright notice and the body and html closing tags.
This is the part, which most of us find difficult to understand, I did too. Well, read it twice, its not that hard. Open your text editting program (I use notepad). Start a new document and copy & paste the following code there:
|
<? $total_skins = 4; $default_skin = 2; if (isset($_REQUEST['newskin'])) { $newskin=(int)$_REQUEST['newskin']; if ( ($newskin<1) OR ($newskin>$total_skins) ) $newskin=$default_skin; } elseif (isset($_REQUEST['skin'])) { $newskin=(int)$skin; if ( ($skin<1) OR ($skin>$total_skins) ) $newskin=$default_skin; } else $newskin=$default_skin; $skin=$newskin; setcookie ('skin', "", time() - 3600); setcookie('skin',$newskin,time()+(86400*365),'/'); setcookie('skin',$newskin,time()+(86400*365),'/','.BLAH.COM'); $skin=$newskin; $headervar = "/home/USER/public_html/skins/$newskin/header"; $footervar = "/home/USER/public_html/skins/$newskin/footer"; $extension = ".php"; ?> |
Open the body.php file you made, right on the top (before any code) add this line:
| <? include("/home/USER/public_html/skins/cookiecheck.php");?> |
| <? include($headervar.$extension); ?> |
| <? include($footervar.$extension); ?> |
Some people like to use a file called index2.php when they skin the site, I don't use it, because I don't liek it and besides I never understood how to..lol! Its not required either, its just a page which opens everytime the visitor changes his skin on your site, saying "you have now switched to skin "this" browse ahead if you like it, or go back to pick another one"...I think thats pointless, the visitors know they switched skins so yeah... I don't use index2.php. Connect to FTP, on your server make a folder called skins. Upload the cookiecheck.php in that folder. Now, lets say you have 3 skins, inside the skins folder, make 3 new folders names 1, 2 & 3. Upload the header.php and footer.php (if needed, the css files, images etc. too) of each layout u made in their respective folder. Come to the root directory, that is, the main directory of your subdomain or domain (where you put the index.html or index.php files when your site was not skinned). Upload the index.php there. Now go to your site: http://blah.com/index.php If you see the default skin of your site (the one you made default in the cookiecheck.php file) showing fine, then you did everything right! (however, I don't think anyone can do it right at once lol! not me atleast) , if you see some errors the first time, don't worry, try again. Read the tutorial twice or thrice if needed. If everything was right, you can change your skins now! To change the skins use this tag:
|
<a href="?newskin=1">Skin 1</a> <a href="?newskin=2">Skin 2</a> <a href="?newskin=3">Skin 3</a> <a href="?newskin=4">Skin 4</a> |





