Content Architecture
You should think about site architecture before you create your first content page. Site architecture should be arranged so that you can
make global changes to the look and feel of a site with no impact on the content. You also want to be able to change the code for an ad
programor even swap one ad program for anotheronce and have the changes take effect across your site in all the content pages.
Server-Side Includes
The simplest mechanism for implementing a "change code in one place, change the whole site" architecture is to use server-side includes
Most web hosting accounts provide a server-side include mechanism. You tell the web server which file extensions mean that a file can
have includes. When the web server processes the file to send back to a browser for display, it looks for the special syntax that means
there is an include. When it sees this syntax, it expands the page it is serving to the browser by expanding it with the file indicated by the
include's syntax.
The default file extension for a web page is usually .shtml, although you can add other file extensions so that your web server will look
through them for includes (there is, of course, a slight performance hit for this).
For example, suppose you have a simple .shtml home page like this:
Hello!
...
You could create two include files:
styles.html , which contains CSS (Cascading Style Sheet) styles for the elements used on the site such as font size and color
top-bar.html , which contains the site navigation bar
You can link to an external CSS style sheet, or define your CSS styles in an include file. Either way, to
change styles sitewide, you just have to change the style definitions in one file.
The site home page, and every other content page on the site, includes these two files as follows:
Hello!
...
Now it's easy to change the appearance of the text on each page of the site by just making one change to styles.html. And if you need to
change the appearance of the navigation bar, you can simply make the changes to top-bar.html, and it will be replicated across the site.
There's generally no requirement that included files be named with any particular file extension; instead
of .html you can perfectly well use .foo, or anything else you'd like.
PHP Includes
If you are constructing a dynamic site using PHP
Most Linux and Apache based web hosts provide PHP scripting automatically for files named with a .php file extension. Within these files,
PHP includes work almost exactly like server-side includes.
For example, suppose you have a simple little web home page in a file named index.php:
...
If you put the CSS styles for the elements of the web site such as the appearance of web site text in a file named style.inc, it can be
included in PHP code like this:
The code for the top portion of a page, to be shared in common across the site, might be put in a file named top.inc. It could now be
inserted at the top of the body of a content page using the PHP include directive:
...
As with the server-side include example, if all the pages in a site use the PHP directives to include style.inc and top.inc, then site styles and
the top element can be changed globally just by changing the contents of these include files.
Note that you can include PHP codeincluding other PHP include directiveswithin PHP includes and that there is no requirement that
includes be named with any particular file suffix.