Saturday 8 January 2011

Navigation Bar Links

Friday 7th January 2011


All the following is the text from the webpage www.RichsWebArchive.com/aboutthissite/navbarlinks/index.php and it reads as though you are viewing the actual page:

It occurred to me that the links in the navigation bar can and indeed should stay the same from page to page of the site. So I wanted to have 1 piece of code for the links which I could then call from any page I choose. Thus if I change a link I only need edit one file instead of many.

I wanted a method of importing html into html.

A quick Google search and a bit of reading led me to believe that using a php call include was the easiest way to go about things. It turns out that it was pretty simple too. More of an issue was being able to test pages containing php without having to upload them to a server and this is discussed in the My Sytsem page.

It was really easy to do. I copied the code for the links into a seperate file called navbarlinks.inc, which I saved in the site's root directory/folder. Only the code for the links, not their surrounding div tags. In place of the links in the main XHTML document I put the following line:

<?php include('../navbarlinks.inc'); ?>

This copies the code from navbarlinks.inc directly in it's place.

All that then remained to do was to change the extension of the index.htm file to .php. This tells servers to parse the page for php and translate it into html before they send the page to your browser. I had to upload the files to my server before I could tell if it worked.

Luckily this was one of those rare and joyous occasions where everything worked absolutely right first time. I then went on to getting the php to work locally. That took a bit more time, but it was free and pretty smooth.

Once again, all the preceding text is from the webpage www.RichsWebArchive.com/aboutthissite/navbarlinks/index.php and it reads as though you are viewing the actual page:

No comments:

Post a Comment

keep it nice now