|
|
New Page 1
How to use PHP includes on your page for faster (and simpler) editing
PHP includes ...what the hell is an include? Simply
put, when you are designing a website, you want your site to be as
streamlined as possible. If you have a 3 or 5 page site, and one day
you decide to change the default logo that you use, well that's no big
deal ...it's only 3 or 5 pages you need to update.
What if your website is over 1,000 pages? Ahhh, now you see that you
need a better method of updating your site "all at once" ...obviously,
updating 1,000+ pages every single time you want to change something isn't
practical. Unless you're just bored, or a loner, or both. This
is where the "include" comes in.
Quite simply, an include is just what it sounds like ...it's content that
you can (take a guess...) ...include in your website. Here's an
example:
This website, imnotcartman.com has quite a few pages (easily over 100).
The site logo (at the top of this page) is on every page. Well, if I
wanted to change the logo to reflect across the whole site, that would be
quite a chore, wouldn't it! So, what I've done is create an include
page somewhere else on my site (in this case, in the root/inc/ folder).
Each time I want the logo to appear (ie: on every page), instead of typing
this:
<img
src="http://www.imnotcartman.com/images/logo.jpg"
align="center">
I type this:
<? include("inc/top.php") ?>
(I try to name my files so they are somewhat recognizable. You
can call yours anything you want ...logo.php, header.php, etc.)
Every place on my site, regardless of location, that I type <? include("inc/top.php") ?>,
the following code is output automatically in it's place:
<html>
<head>
</head>
<body>
<table bordercolor="#111111"
width="90%">
<tr>
<a href="http://www.imnotcartman.com"><img
src="http://www.imnotcartman.com/images/logo.jpg"></a>
<br>
</tr>
</table>
</body>
</html>
I left a lot out of the actual page (scripts and other code), just
for simplification. Hopefully, you can see how using PHP includes
can make designing a website MUCH simpler! Now, if I get a wild hair
to change my site logo (or to add a navigation menu below it, etc), I just
edit the include file (inc/top.php), save it, and my site is completely
updated!
PHP includes are cool.
I hope this little tutorial was helpful to you :)
Go back to Site Design index page
|