|
« Previous |
Home
| Next »
|
|
|
March 27, 2007
One of the things I cover in my course Introduction to Web Site Creation is using include files to build web pages. An include file is a file that's called or included from another file. A menu, footer, or header is a good example. If your menu, footer, or header is the same on each page of your web site, instead of repeating that section of code on each page, why not have just ONE file for the menu, and one file for the header, etc. You then reference that file from the main code of your web page and it's included as if its code is part of the main page. The great thing is that when you need to change your menu, footer, or header, you only have one file to edit instead of having to edit all the pages of your web site.
Different scripting/programming languages have different syntax for including files; I'll cover PHP here.
One way to approach the initial creation of a page or web site that uses include files is to create the whole page without the include files, and then cut out the sections of code you want to put in include files. I recommend NotePad+ as a good HTML / Code editor (it's Free!).
For example, let's make a menu with two links in it; put this code in a file called incMenu.php:
Then, from the main page, index.php and/or the other pages in the web site, we'll call or Include incMenu.php. You'll put the following statement in index.php where you would normally have put the contents of the incMenu.php file (the two links in this example):
When someone browsing the Internet requests your web page, your web server's PHP engine processes your index.php file and sees the include statement (require) and gets the incMenu.php file and puts it's content into the output that's sent to the end user. In other words, the server replaces the statement with the contents of the incMenu.php file on the fly. One thing to keep in mind if your server is a Linux/Unix server, is that capitalzation counts (it does not on Windows based servers). So if you name your include file "incMenu.php", you need to reference it from the main files (index.php for example) with the same letters capitalized, "incmenu.php" will not work, you need to use "incMenu.php".
You can use this same technique for headers, footers, sidebars, etc., any part of a page that gets repeated on multiple pages.
The one down side to using include files is that it's harder to layout and edit your pages because parts of your pages are now in more than one file. However, it can save you a huge amount of time because you only have one file to edit vs. editing every page of your web site.
Want to learn more? Get my courses Introduction to Web Site Creation which covers include files and more, and also Web Site Scripting which covers basic php scripting and forms.
Fred
About the Author
Fred Black is an experienced programmer, web site developer, online business operator, systems integrator, father, husband, musician, and songwriter. Visit his Internet Business Blog at: http://www.pqInternet.com.
|
Posted by Fred on March 27, 2007 | Printer-Friendly
TrackBack: http://www.pqInternet.com/Blog/mt-tb.cgi/34
Assigned Categories:
Web Site Design, HTML, CSS
Related Entries:
|
You may reprint or distribute this article as long as you leave the content and the About the Author resource box at the end intact. |
|
|
|
|
|