How to Make a Menu a Separate File on a Website

How to Make a Menu a Separate File on a Website thumbnail
How to Make a Menu a Separate File on a Website

Creating a separate file for a website menu makes it easy to place the exact same menu on all pages of the site. The PHP server side scripting language allows you to do this by using the "include" function. When a change needs to be made in the menu, there is only a single file that must be edited. Otherwise, the menu must be edited on every page of the website.

Instructions

  1. Menu

    • 1

      Open a blank document in any text editor.

    • 2

      Create the menu with the following code:

      <a href="http://www.test.com/index.php">Home</a>
      <a href="http://www.test.com/writing.php">Example Articles</a>
      <a href="http://www.test.com/references.php">References</a>
      <a href="http://www.test.com/contact.php">Contact Me</a>

    • 3

      Save the file as "menu.php" and place it on your web server.

    Main Document

    • 4

      Open a second blank document in a text editor.

    • 5

      Start the HTML document with the following code:

      <html>
      <body>

    • 6

      Type the line "<?php include("menu.php"); ?>" to include the "menu.php" document.

    • 7

      Add the remaining HTML and PHP code for your web page.

    • 8

      Finish the HTML document with the following HTML code:

      </body>
      </html>

    • 9

      Save the document as "index.php" and place it on the web server.

    • 10

      Test the menu by opening the "index.php" document in a web browser.

Related Searches:

References

  • Photo Credit Ciaran Griffin/Lifesize/Getty Images

Comments

You May Also Like

Related Ads

Featured