-1

For small business websites, let say about 10 pages, is there any "common practice" to structure files?

What I normally do is, make a header.php, a footer.php, then all individual pages. in header.php. I put all html head tags in the individual pages like this

<?php //some php if needed?>
<!DOCTYPE HTML>
<html>
<head>
<title>my site</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<meta name="description" content="some descriptions" />
<link rel="shortcut icon" href="images/favicon.png" type="image/png" />
</head>
<body>
<?php include_once "header.php";?>
<!--different page contents here-->
<?php include_once "footer.php";?>
</body>
</html>

In header.php and footer.php, i only put common contents like menu and contact infos. The good thing for this approach is things in head tag like title tag and description meta tag can be easily changed, also different scripts and css can be included as per different pages. The bad thing is whenever anything changes in here I need to change it in every single page.

So I am just wondering what is the proper way to organize them? I have been looking into this problem for quite a while, here are some of the posts This and This and This, thanks

Community
  • 1
  • 1
Andrew Liu
  • 2,478
  • 5
  • 22
  • 29
  • You halfway answer your own question. Put anything that's common between the pages in a shared file and include that. If it's unique, you put it in the individual page (like the ``) – Deryck Jan 24 '14 at 06:12
  • You can also use a MCV pattern (inside a framework or done by yourself) to avoid repeating HTML code. Maybe is not the best solution for your case, but it's an option. More info: http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller – Dani Sancas Jan 24 '14 at 06:30

2 Answers2

1

Not to troll, but you're describing the need for a PHP content management system, like WordPress or Drupal. That's exactly what they do.

There's no performance advantage to using PHP in the architecture you describe as opposed to creating separate HTML pages and including header and footer in them. Maybe it saves a few minutes over the course of a month, but you lose most of the automation features that make content so manageable. Plus CSS is a headache, and databases are more challenging. etc, etc.

Ross
  • 305
  • 1
  • 2
  • 10
  • cms like wordpress dont have any head tags in the page template but they can have different meta informations in different pages, that is what i am trying to learn from here – Andrew Liu Jan 24 '14 at 06:23
  • In that case, you could include more php files, which allows you to recycle the structure of other pages more frequently. page.template.php or sidebar.php would give you a lot less copy->paste in the long run – Ross Jan 24 '14 at 06:42
1

Following "good practices" will make your site look like a copy of a CMS output.

You will have the usual "fluid" design imposed by the CSS nazis, the unavoidable accordion imposed by the JQuery zealots, your odd silly spinning wheel to make sure even the dumbest visitor can recognize your site as a true Web 2.0 marvel of technology, your mandatory h2 and h3 tags full of advertising and your useless meta data to please the Google God, etc.

My advice would be to start with a graphic designer who knows nothing about the bloody web, and try to implement what he/she imagined. You can then handle the problem like you would any software design.

You will soon apply common sense to this design, like factorizing bits of similar data and processing, picking modules, algoriths and code snippets from all over the Internet to avoid reinventing the wheel, etc.

That is what will stray from the "good practices" that will make your site stand out and be worth viewing, IMHO.

kuroi neko
  • 8,479
  • 1
  • 19
  • 43