HTML Menu - write once and include

Soldato
Joined
6 Mar 2008
Posts
10,079
Location
Stoke area
Hi all,

Creating my own photography site using Bootstrap, my html and css is ok, I can get by and understand a fair bit, javascript and php are rubbish and the reason for building my sites so I have places to learn.

Instead of me writing my menu out and editing it in each html document, then having to edit everyone each time I add a page, what is the best way of having a single menu file and just importing that into each page?

Would you then use Javascript to find which link is the active one and adjust the menu accordingly so the active page would be highlighted in the menu?
 
Associate
Joined
14 Nov 2006
Posts
2,057
Location
UK
Take a look at PHP includes.

Your main pages will need to be a PHP file for it to work.

What you need to do is cut out your menu HTML and paste it into a new file, name it 'navigation.php' for example.

Then where your menu HTML was, simply write this:

PHP:
<?php include("navigation.php"); ?>

And it will include the HTML from the navigation file into your document.
 
Soldato
OP
Joined
6 Mar 2008
Posts
10,079
Location
Stoke area
Yeah I tried php includes as well as some html includes I found but no joy.

I've created menu.php that holds the header div with the nav bar information in it.

I've then used <?php include("menu.php"); ?> inside a container div within the new php file. Just shows a blank screen. I've popped a <p> tag afterwards and that appears but 1/4 of the way over the line.

Think i'll have to try it on a live server instead of the usbwebserver, see if it's something on their playing up.
 
Back
Top Bottom