PHP Include

Every web site needs a navigation system and maintaining this navigation system can be a nightmare, especially if your site has grown to hundreds of pages.  Each time you add something, or simply need to update a link, you have to open every page to update the menu.  The solution is PHP include.

Basically, the idea is that the menu is stored in a single PHP file and then an include command is used to include the menu on each page.  This means that when changes are made to the file structure of the site, only one menu file needs to be updated.  Sound good?

STEP 1

The first step requires changing each of your HTM or HTML files to PHP.  This is simply a case of renaming the file extensions, for example “index.htm” will become “index.php”.

STEP 2

Next you will need to create the “menu.php” file.  This file must only contain the menu, no <head> or <body> tags.

menu

STEP 3

Last, include the “menu.php” file in each page you would like the menu to appear.

To do this you simply need to use the following command where you would like the menu to appear:

<?php include('../menu.php'); ?>

In the background, the server will place the menu code into each page that this command appears.

CHouseLive Software

TIPS

Remember, you will need to ensure PHP is installed on your server in order for this to work.  If you wish to view your pages locally, you’ll also need to install PHP on your own computer as well as a local server.

0 comments:

Post a Comment