Adding External Navigation to Your Website with PHP
First, you’re going to want to prepare your website to work with PHP. It’s as simple as opening your webpages and re-saving them with the file extension “.php” rather than “.html”! Keep in mind that this needs to be done for every page on your site.
One thing you may notice is that I went out to my host to display the page, rather than pull it up from my hard drive. This is because to use PHP, you need a PHP server. Hosts like this have the functionality by default, and if you want to test your website locally, I’d recommend using XAMPP.
With all the technical stuff out of the way, let’s get into actually writing some code. Below, we have our standard PHP/HTML amalgamation, with a standard HTML5 navigation layout.
This code references the file “navigation.php” and tells the
browser PHP server to look there, where it will find the code below.
This code is basically injected into your webpages where you placed the PHP include statement, and the web browser reads it as HTML. Without any styling, this is the result of your brand new external navigation.
And there you have it, a navigation scheme where only one file needs editing to make changes across your entire website! And remember, the code coming from PHP is no different to the browser than HTML, so it can be styled and worked with just like you would with HTML.
~ by ryanwcraig on September 10, 2012.
Comments are closed.