Simple PHP template

Have you ever wondered how to create a simple PHP template for using on your web site? This tutorial will explain the concept and in the end you will see some code examples. The concept of templates is that from one simple index file we include some other file based on GET variables. If you don’t know what a GET variable is this tutorial may be over your head and I suggest you learn this otherwise.

The advantage of using templates are:

  • Easy to maintain
  • Easy to change design
  • Consistent look

Here are the simplified code for index.php



// Code for including css file
...


// Code for menu etc.





All you need to do now is create the individual pages. If you want additional pages all you have to do is create a link in the menu and make an include statement in the switch block. The pages should only contain text and/or html, all the styling should be in a css file included in the index file.

6 Responses to “Simple PHP template”

  1. Help Quit Smoking 2006/03/13 22:30

    This is a great site for PHP help. Thank you so much for the content is not priceable! This will help me a ton

  2. Adri 2006/04/06 06:44

    Tanks

  3. somf 2006/10/25 12:18

    Pity this doesn’t work!

  4. rso 2007/02/13 00:13

    try to add break statement…then this example will be more functional.

  5. Free 2007/08/25 10:29

    Horny cam girls, free live video chat…

  6. jack 2008/08/17 22:02

    this does work, works like a charm. the only thing is it needs you to add one thing to the code: after every case ‘blah’: include(“blah.inc”); statement you need to add a break; statement to stop all of your included files appearing at once.

    once i added that i found that this little wedge of code does pretty much everything i was hoping. might need to investigate possible abuses of the $_GET variable but they’re probably quite easy to resolve.

    good job whoever came up with this :D

    jack

Leave a Reply

You must be logged in to post a comment.