This week on The Killersites Forum Blog, we take a look at a really insightful post from the Killersites Forum on how to create repeating sections of code on numerous pages.
Question:– I’ve got a site with 100 pages and I don’t want to edit the
menu on every page.
Answer:– Form one page complete in the normal way with the menu and
check that it validates and displays properly.
Open up Notepad or a text editor (not Word) and cut the code that
repeats in every page completely (as much or as little as you want,
without doctype, html, head or body tags) and paste it into Notepad and
save as an “include” file called menu.inc. You then have only one file to
edit if the menu changes.
Substitute the code you have cut out with PHP code
in the main file and save it with .php filename extension instead of .html
Do the same with other main pages where the menu repeats.
You can use .txt, .php, .html or .htm for the “include” file but it
distinguishes it as an “include” file in your file list if you use .inc as the
filename extension and it’s even better if you put all “include” files in a
If you use a complete page as an “include” file with .html or .htm for the
filename extension the final processed page will have two doctypes, two
html tags, two head sections, etc. in an unusual place which is not a
You can have different “include” files on the same main pages for header
and footer and even use “includes” for the parts of the head section that
The PHP code needs to be processed by a server before the result can
be seen, either by the hosting service’s server just before downloading or
by a server like WAMP (which includes Apache) on your computer for
SHTML works the same way but the “include” file must have .txt
filename extension and the main pages have the code and the .shtml filename extension.
Check that your hosting service supports PHP or SHTML as free
webspaces provided by ISPs usually do not.
Not sure if this is in the videos – but it’s generally a good idea, especially if the site is set up with sub-folders, to use the absolute paths pointing to the include files, and for anything the include itself points to – that can save a lot of wondering why something suddenly isn’t showing up.
Written by: Wickham
You can take a look and get involved with the original post and discussions here!
This entry was posted on Monday, November 22nd, 2010 at 6:51 am and is filed under Forum Blog. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.