N. Chalifour N. Chalifour - 2 months ago 9
PHP Question

Navigation bar in html5

I have a quick question. I'm wondering if it is possible to have a external html file with my navigation bar in it and have that be put in to all of my pages for my website. If so how do I do this? I have tried using these methods:

<script rel="import" src="navigation-bar.html"></script>

$("#nav-bar").load("navigation-bar.html")


but so far neither of them have worked... Do I have to use PHP and if I do how do I implement this.

please help.

Answer

I would use PHP to do this.

Here is the structure of how it would work.

 <html>
 <head>
 <?php require('/directory/to/your/header.php'); ?>
 </head>
 <body>
   ...Your Content Here
 </body>
 </html>

In a separate header.php file you would include your navbar.

Header.php

 <?php 
   echo '...enter your Navbar HTML code';
 ?>

Your file will have to have the extension .php and every time you write in php, you must start and end with

 <?php 
    ...enter your php code...
 ?>

You can mix php with html simply by writing the php into the HTML. Take for example the following href:

 <a href = "<?php echo 'www.yourlinkhere.com'?>">Your link Name</a>

For more information please refer to : http://php.net/manual/en/