Nobody likes frames. But if you're not using frames, you have to update every
page of your site every time you modify your menu. Don't you wish there was another
way? Well, there is. Simple PHP includes allow you to create a professional,
frameless site without too much work. Want to learn how? Read on...
PHP includes are very simple and really practical. How they are used is they
allow you to use one line of code in every page that you want your menu on in
place of say 30 - 50. Also, you never have to edit this code once it's there,
you can just edit your menu file. They work by taking all the content of a file
and putting it into the file being viewed at the location where the INCLUDE tag
is.
I'll start off by teaching you how to create a basic site that uses a menu in
tables. Run Notepad and create a file for your menu, in a table. It might look
something like this:
<table border=0 bordercolor="black" cellspacing=0 cellpadding=0 width=780
height=100%>
<tr>
<td width=100 valign="top">
<img src="main.jpg"><br><Br>
<a href="index.php">News/Home<a><Br>
<a href="index.php?page=stuff">Stuff<a><Br>
Blah<Br>
Blah<Br>
Blah<Br>
Blah<Br>
Blah<Br>
Blah<Br>
<td>
Make sure that you do not close the table!! Now save this file as menu.php
and start a new one. It'll have the code for you main page. It should look something
like this:
< include("menu.php") ?>
<td width=580 valign=top>
<
if(!$page) {
include("http://www.hobbiton.org/~zeroone/test/news.txt");
}<Br>
else{
include("http://www.hobbiton.org/~zeroone/test/files/" . "$page" . ".php");
}<Br>
?><Br>
<td>
<tr>
<table>
There are two vital things you should notice here. First, we have the <
include("menu.php") ?>. This tells the computer to include the menu file.
The second thing is this code:
<
if(!$page) {
include("http://www.hobbiton.org/~zeroone/test/news.txt");<Br>
}<Br>
else{
include("http://www.hobbiton.org/~zeroone/test/files/" . "$page" . ".php");
}
?>
Make sure you change the URLs to URLs on your server. This code tells
the computer that if the url is something like "www.yourpage.com/index.php"
then it will include the news file, in this case (since I've set it to the URL
of my test site's news file).
IF, however, the URL is something like "www.yourpage.com/index.php?page=stuff"
then it will change the content of the page to whatever is in the file "stuff.php".
At this point, there is something I should mention. When you have links on a
php page, they will be something like "www.yourpage.com/index.php?whatever=pagename"
instead of something like "www.yourpage.com/pagename.php". This
is because the web browser is actually displaying the index file, but it's including
content from another file on the index file. The "whatever=pagename" tells the
computer that the variable "whatever" is set to the name of the page, "pagename"
in this case. That variable tells what page's content should be displayed, using
the code above.
Conclusion
Next, create another file. Just type some nonsense in it and name it "stuff.php".
In your menu file, make sure you have a link to "stuff.php". The link should
be something like "http://www.yoursite.com/index.php?stuff" because
of the reasons I mentioned above.
Now, upload those files and see what it looks like. It SHOULD look a little bit
like the site http://www.hobbiton.org/~zeroone/test
- please note the server that site is on is going down permanently soon, so you
may not be able to access it.
If that all worked out, you've got a simple PHP layout. Play with it a bit, and
you'll be able to implement it into your site's design to make being a webmaster
easier. I hope this tutorial was helpful.