Tutorials, Articles, Tools
Tutorial written by Cine
Requirements: A server with PHP, basic HTML knowledge and a couple of minutes to spare.
Okay, so lets say that you have a really big site, with lots of pages. Each time you want to change your layout, you have to go through every single page, and change it so it matches all the other pages. And as you probably know, that can be a lot of work, something most of us would like to avoid doing. So is there a way to avoid this?
There is! Using PHP and the function include(), you can avoid having to change all your pages each time you change your layout! And this tutorial is going to tell you how to do it.
Now, as a start, lets say the following is what your index.html page looks like. In the same directory as your index file, you've also maybe got a file called me.html, one called visitor.html, links.html, yes - you've got lots of pages! Each page has the same coding and the only thing that differs is the content.
So, the first thing we're going to do, is to rename all our page extensions to php, instead of html. That means, you've got to go through all your pages and rename index.html to index.php, me.html to me.php, visitor.html to visitor.php and links.html to links.php.
Once you're done with that, we're ready to create the header and footer files! First, look at the HTML of one of your pages, and copy everything that is over the content. Open Notepad, or another plain text editor of yours, and click paste all the coding you copied into a empty document. Save it as header.php, and make sure you select "All Files" from the Save as Type dropdown! This is what my header file looks like:Notice how just before it's the content's turn to enter the stage, we cut it of? Great. Now, lets create the footer file! Look at your layout HTML again, and copy everything below the content this time. Save it as footer.php and upload it together with your header.php file. Your footer file should will look something along the lines of this..
Just one more step left, now! Open all your files in your HTML editor, and remove the layout! Strip down the page so that the only thing left is the content. Then, add <?php include('header.php'); ?> above your content, and <?php include('footer.php'); ?> below your content. Your files should look something along the lines of this when you are done.
Look how much less you have to type on every page! What the function does, is to check for the header.php & footer.php files, and include them to the page if they do exist. Useful, eh? :)
Now, save and upload your files. If you've done everything correctly, the page will look exactly the same, and so will the source, but next time you want to change your layout all you have to do is to change your header and footer files, and all the other files will change as well!
Tutorial written by Cine
Quick Links
Website Search
Member Search
Warning: mysql_query(): Access denied for user: 'nobody@localhost' (Using password: NO) in /home/fdlinda/public_html/quickmenu.php on line 78
Warning: mysql_query(): A link to the server could not be established in /home/fdlinda/public_html/quickmenu.php on line 78
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fdlinda/public_html/quickmenu.php on line 79
Warning: mysql_query(): Access denied for user: 'nobody@localhost' (Using password: NO) in /home/fdlinda/public_html/quickmenu.php on line 81
Warning: mysql_query(): A link to the server could not be established in /home/fdlinda/public_html/quickmenu.php on line 81
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fdlinda/public_html/quickmenu.php on line 82
