logo
Published on Code2Design (http://code2design.com)

You Can CMS Without One

By maspick
Created Feb 9 2007 - 8:08pm

For several years now, I've been creating mini CMS's without realizing it - actually before there was such a term. It's made all the difference in the world in maintaining websites, especially with over 50 sites like we watch over. How do I do it? Thought you'd never ask. :)

This requires either PHP or SSI (Server Side Includes). I'll be talking about the PHP method here, but can show the other if there's a demand.

First step is to create your first page normally and get it just the way you want it. Then examine your source to see what will be repeated on the rest of the pages on the top and bottom.

Whatever part of the code will be repeated at the top of each page, remove from your page and paste into a document of it's own called header.php. The part that will be at the bottom of each page, remove and place in a document called footer.php. In your original document, put the following in place of the contents of the new header.php:

<?php include("header.php"); ?>

In place of the contents of the new footer.php, put the following:

<?php include("footer.php"); ?>

Here's what you should end up with:
Main Document

<?php include("header.php"); ?>

. . .

PAGE CONTENTS

. . .

<?php include("footer.php"); ?>

header.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Site</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="container">

footer.php

<div id="footer">
<p>© 2007 My Design Company</p>
</div>
</div>
</body>
</html>

What this does is allow you to concentrate on the contents of the individual page without weeding through the stuff that's got to be at the top and bottom of each page, which can be extensive depending on the layout. Also, if you need to tweak something in the top or bottom of the pages, you only have to change it in one place and it's instantly changed across every page that includes it.

I hear you saying to yourself, "Well that's cool. I can see where that might save me some time. Is that all there is, though?" Not at all. In the next installment, I'll share some techniques to make this idea "stand up and dance." Stay tuned.


Source URL:
http://code2design.com/maspick/you_can_cms_without_one