Question

Possible Duplicate:
Include one HTML file in another HTML file

On each of the pages on my website I have a footer that contains about 12 links. Every time I want to change a link, I have to do it on every single page. Is it possible to make it so I can somehow change the link in one place and it changes on every page? Thanks.

Was it helpful?

Solution

This exact problem is the beauty of serverside scripting, where you can define a header file that each page pulls from when it is retrieved, allowing you to change a single file and have the changes propagate your entire website.

This is what it could look like in PHP:

header.php - <a href="link">Link</a>

all_other_pages.php - <?php include header.php; ?> ...

OTHER TIPS

the better approach is use the mvc architecture for that . and you can do it by creating the separate php file and include them

like for header header.php for wrapper wrapper.php and for footer footer.php and to show a pagge just include or require them

like index.php

   <?php
     require"header.php"; // for the header of the page 
     require"wrapper.php";
     require"footer.php";  // for the footer of the page 

you can also make function of header() and footer() so you can also include many more function in a file and it reduce the amount of file also you only need to include the one file with function

index.php

 <?php
      require"function.php"; 
      header();      // for the header of the page           
      require"wrapper.php";
      footer();       // for the footer of the page

in above approach the code of header and futtor will be universal for all website what you need to change is the chande the code in wrapper.php

You don't need to do server side programming to fix this (though you can do), you can do it perfectly fine in the browser with a little javascript.

For example: at the bottom of each page:

<div class="page-footer"/>
<script src="footer.js"></script>

in footer.js something along the lines:

$(".page-footer").append("<ul><li><a href='about.html'>About</a></li></ul>");

If you can use a server side include or other server side programming then yes, otherwise it isn't posible with straight HTML. You could include the footer in an IFRAME such that each page loads the same footer page, but this is far from an ideal solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top