Using PHP for Easy Menu Updates

Article by Simon Hill (28,945 pts ) , published Jul 29, 2009

Do you want to be able to change your website menu in one file and have it update throughout your website? Try using PHP. In this simple tutorial you can learn how to use PHP to make updating your menu, header or footer as simple and easy as possible.

The Problem with HTML Menu Updates

One of the first problems you may run into when developing websites with HTML is the laborious nature of menu updates. If you want to add a new section to the navigation menu of your website you have to add it to each separate HTML file and if your website has several pages this soon becomes a time consuming and boring task. Wouldn’t you prefer to be able to have a separate file for your menu, your header and your footer? That way you if you make any changes you only need to edit one file and the entire website will be updated.

The Advantages of PHP

Now you have probably heard of PHP. You can use PHP to do all kinds of fancy things like dynamically creating new pages, building user input forms and returning queries from an SQL database. However you can also use it to make updating your menus nice and easy and it is very simple to set up.

If you’ve taken the time to learn HTML and CSS then you may be put off by the idea of learning another language but if all you want is an easy menu update solution then you will not find PHP taxing at all.

First of all you will need to make sure PHP is installed on your website server. Many hosting companies provide it or you can install it yourself. Make sure you check this before you begin.

For each page on your website you will need to create a PHP file. You can still use PHP in conjunction with HTML and CSS. Now say we want a simple page with a header, a navigation menu on the left and a footer. You would create an HTML page for each element and one for the content of the page. Use your normal CSS or HTML to order the layout and then create a PHP file to pull it all together. To create a PHP file simply write the code in your normal editor, I use wordpad or notepad and then save the file as a .PHP file.

Subscribe to Web Development
RSS
Get free weekly updates, directly to your inbox.
Browse Web Development