[HTML] Identical content over multiple pages?

Discussion in 'General Webmaster Support' started by LurkerAspect, Mar 10, 2012.

  1. LurkerAspect

    LurkerAspect Check out Elemental Tournament!

    Hi there :D

    I've recently started learning how to make websites with HTML and CSS for university/college, and I was wondering if it's possible to import a specific area of code that I can define outside the website, and use across multiple webpages? In other words, is it possible to create an external file with a few lines of code, then import that snippet of code into multiple web pages?

    Basically I'm making a website with 16 pages, and I don't want to have to modify the navigation bar's links for every single page, which means making about 16 links for 16 pages, which comes out to 256 links I'll need to type out/copy-paste.

    If you're still confused, I'll try to illustrate: Here's the code snippet:
    Code:
    <div id="quicklinks">
         <a href="pg1">Home</a>
         <a href="pg2">Accomodation</a>
         <a href="pg3">Entertainment</a>
         <a href="pg4">Shopping</a>
    </div>
    
    I want to be able to import this snippet so I don't have to write it out again on every single page. Is that possible?

    Any help is greatly appreciated :D
    1 person likes this.
  2. UndeadDragon

    UndeadDragon Super Moderator Staff Member

    The best way will be, if your server supports PHP, to include the file everytime it is needed and then you will update the single file when needed, which will affect all pages it is included on.

    For example:

    navigation.htm
    PHP:
    <div id="quicklinks">
         <
    a href="pg1">Home</a>
         <
    a href="pg2">Accomodation</a>
         <
    a href="pg3">Entertainment</a>
         <
    a href="pg4">Shopping</a>
    </
    div>
    index.php
    PHP:
    <html>
    <head>
    <title>Test</title>
    </head>

    <body>
    <?php include "navigation.htm"?>
    </body>
    </html>
    1 person likes this.
  3. LurkerAspect

    LurkerAspect Check out Elemental Tournament!

    Thanks Undead Dragon, I'll give it a shot :D so far the website is not going live, it'll just be run locally for marking purposes so I'm sure the PHP won't be a problem :) Thanks for the speedy reply!

Share This Page