My Favorite Webmaster’s Trick
Whether you have one website or several dozens… their is one very handy piece of code that can save you tons of work when its time to update your site. Using the PHP include function will allow you to update design or content changes with one quick edit. No need to have to edit each specific page of your site, nor to learn a new programming language either.
Let’s begin by taking a look at a basic index page. There are usually three sections that make up this page — a header, body, and footer. Using traditional HTML code, this outline will look like this:
<html>
<head>TITLE and META tags</head>
<body>
PAGE CONTENT
FOOTER LINKS
</body>
</html>
In order to save ourself a great deal of time, we will use the PHP include function to share common parts of your web pages such as the header and footer. You will want to be sure that your server is running PHP and that your files use the .php extension. You can just rename your .html files if necessary.
Now lets look at the layout of our new index page:
<html>
<?php include('header.php'); ?>
<body>
PAGE CONTENT
<?php include('footer.php'); ?>
</body>
</html>
You will want to create two new files, “header.php” and “footer.php”. You can just copy and paste your normal HTML code into these files and save. Your code will now be automatically inserted into your index page or any other page where you place the include code.
Do you use the same banner and sidebar on each page ? No problem. Just add more includes.
<html>
<?php include('header.php'); ?>
<body>
<?php include('banner.php'); ?>
PAGE CONTENT
<?php include('sidebar.php'); ?>
<?php include('footer.php'); ?>
</body>
</html>
This is definitely my favorite webmaster’s trick and I hope you find this little piece of code as useful as I have.
