Scenario 1: You own a large website, with many pages of a LOT of content. For instance: updating links is a drag because you have to update EVERY single link on EVERY single HTML file. But...there is a much easier way to do this, I give you...PHP Includes!
Basically, what this does, is it will save you a whole lot of time everytime you want to change your layout or update things. No previous PHP knowledge is required, too. All you need is some HTML basics and you're ready to go.
Now into the tutorial. Once you've got your layout ready, open it in a text editor like Notepad. Here's what a basic layout may look like:
Quote:
<html>
<head>
<title>My site</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table border="0" width="90%">
<tr>
<td width="20%">
<p>Navigation</p>
<p><a href="#">Link here</a><br>
<a href="#Link here</a><br>
<a href="#">Link here</a><br>
...</p>
</td>
<td width="80%">
<!-- Here's where your content starts -->
<p>Hello, welcome to my site, here's where I put all my content =D</p>
<!-- Here ends your content -->
</td>
</tr>
</table>
</body>
</html>
|
Step 1:
Take this piece of code (or everything above where your content starts) and cut and paste it into a separte document. You should have something like this:
Quote:
<html>
<head>
<title>My site</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table border="0" width="90%">
<tr>
<td width="20%">
<p>Navigation</p>
<p><a href="#">Link here</a><br>
<a href="#Link here</a><br>
<a href="#">Link here</a><br>
...</p>
</td>
<td width="80%">
<!-- Here's where your content starts -->
|
Still with me, here? Okay, click Save As and name the file as header.php. Now back to the rest of the layout: take the bottom part of your design and cut and paste it into a separate document. It should look like this:
Quote:
<!-- Here ends your content -->
</td>
</tr>
</table>
</body>
</html>
|
Save this as footer.php. Now, let's get to the magic part...take your content, it can have ANYTHING you want in it. In this case, it would be:
Quote:
|
<p>Hello, welcome to my site, here's where I put all my content =D</p>
|
And add the bold:
Quote:
<?php include('header.php'); ?>
<p>Hello, welcome to my site, here's where I put all my content =D</p>
<?php include('footer.php'); ?>
|
Save this separately as index.php. Upload header.php, footer.php, and index.php to your host and it's all there! So let's say you make a typo on one of the links (it happens!), all you have to do is edit header.php (or wherever your links are) and fix the error, instead of all 50+ pages. Have fun with it!
|