3.5. Expanding Your Web Site

Problem

You need to add pages, a new section, or a distinct subsite to your web site.

Solution

You should design your web site only once, not each time you create a new page. Follow these code and site management techniques to make sure every page on your site has a consistent look and feel:

Separate shared code blocks into include files.

When you save common elements of your site design as include files, you can be sure that the content, wording, and links are the same on every page where that include file appears. For example, if you put all the code for your primary navigation in an include file called primnav_inc.php, then a change to your main navigation requires editing just one file, rather than every page on your site. You can follow the same strategy for other discrete blocks of code, such as the page header and logo, other navigation blocks, and the page footer.

Isolate content from display rules using CSS stylesheets.

In the days before reliable browser support for (and widespread use of) stylesheets, web designers would specify background images, link colors, font sizes, and other display characteristics in the individual tags on every page of a web site. When an inevitable change became necessary, every page on the site had to be edited and re-uploaded to the web server. The process is tedious and introduces the risk that an inadvertent change might mangle the code. Putting the display rules in every page also increases the file's size.

Separating ...

Get Web Site Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.