rs19
rs19

Reputation: 667

how do i insert code that appears on every page on a site?

i'm looking to take some html, mainly the navigation bar and code:

<div id="navbar">
        <ul> 
            <li><a href="">Buy</a></li>
            <li><a href="">Lookbook</a></li>
            <li><a href="">About</a></li>
            <li><a href="">Contact</a></li>

        </ul>
    </div>

and insert it on every page on a given site. how would i do this so that when i make changes it reflects on all the pages, so i don't have to copy and paste the changes on each page.

Upvotes: 1

Views: 4677

Answers (3)

GeekByDesign
GeekByDesign

Reputation: 436

Creater a header page! Create a new page with the .php extension. For this example, call it someheader.php

Include the following code in every new .php file between the <html> tags:

<php 
include('someheader.php');
?>

This saves time since it won't be neccessary to retype the same code over and over.

Upvotes: 0

Gaj
Gaj

Reputation: 46

  1. Add a empty div on all pages.
  2. Create a common java script function that will insert the above html to those Empty div.
  3. Call that javascript function on all the pages.
  4. This method is good only if you are working with Static HTML pages without any server side script.

Upvotes: 2

Always Learning
Always Learning

Reputation: 5581

One way is to have your pages in PHP and include a common file into each of them. That would let you make changes to your navbar and all pages would pick them up. It would require changing your pages to PHP and adding appropriate include statements in each though.

Upvotes: 0

Related Questions