1. Home
  2. Computing & Technology
  3. Personal Web Pages

"Includes" Make Changes Easy
Small Code Makes Life Easier

By , About.com Guide

An "Include" is really something simple. You can change your menus, ads, pictures and other things on your site all at once with very little effort with Includes. Includes let you just change one piece of code and all your pages will be fixed.

For example's sake, let's say you want to add a navigation bar, or menu, to the left column of your Web page. When you add a page to your Web site you also want to add the name of that page to the menu. Normally to do this you would have to change every single page, adding the new link and page name to every single page. After you add this new code to all your pages, where your menu code now is on your page, you will never have to do this again. All you'll have to do is change the code on the Include and it will automatically change the menu on every page you have the Include code on.

Creating an Include

1. Open a New File - To get started, go to your HTML editor and open a new, blank page. Staying with the main menu example, name the new page "mainmenu.txt" (without the quotes).

2. Copy Code - In your HTML editor open one of the pages you want to have your new menu on. Copy your menu code from your Web page and paste it into the blank "mainmenu" page.

If you don't already have menu code on your Web page, just create it here on this blank page. All you need is that little section of code. Save the page when you're finished adding the code and upload this file to the same place on the server that the pages you are going to add the menu to.

Simple Sample Main Menu Code

3. Replace the Code - Replace the menu code on all your pages with the Include code. If you are adding a menu to your Web pages for the first time, decide where in your HTML code you want your menu to be and add the Include code there. This is the Include code you want to add:

<script type="text/javascript" src="includes/mainmenu.js"> </script>

Notice in this code that I added the name of your menu page, ie. mainmenu.txt. You must add this new code to all the places on your Web site where you want the particular Include to show up, replacing the old menu code.

4. Re-Upload - Once you upload the Include to your Web site and re-upload all the pages you added your include to you will see your menu on your pages. Now changing your menu will be a cinch.

Changing the Code

When you are ready to change your menu and add a new link to your Include, this is all you need to do:

1. Open Include - Open the include called "mainmenu" in your HTML editor.

2. Add Text, Link, Picture - In this example we are adding a new link to the menu. Other things you can use Includes for are special messages, pictures, ads or whatever you want. Just add the new link code to the rest of the code in your Include or change the text and link if you are making a change instead of adding a link.

3. Re-Upload - Once you re-upload the Include to your Web site all the pages that you have this Include linked from will be changed.

Create Ads On Your Site

So you want to make money from your personal Web site, but you don't want a whole lot of work. Use Includes to manage your ads. Instead of adding menu code you are going to add ad code to your Include.

1. Join an affiliate program - You must sign up with an affiliate program or have someone willing to pay for ads on your site in order to place money making ads on your site.

2. Decide On An Ad - Choose an ad from your affiliate program and decide where you want to place the add.

3. Create an Include - Create a blank page called something like "ads.txt" (without the quotes). Add the ad code from your affiliate program to the page. Save the page and upload it to your site.

4. Add Code - Add the Include code to all the places on your site where you want this add to show up. The code will look like this:

<!--#include virtual="/includes/ads.txt"-->

Notice that the page name in this code is the name of your ad code, ie. ads.txt. You must add this new code to all the places on your Web site where you want the particular Include to show up.

5. Re-Upload - Once you upload the Include to your Web site and re-upload all the pages you added your include to you will see your menu on your pages. Now changing your ads will be simple. Just follow the same instructions for changing the ads as you would for changing the menu.

Explore Personal Web Pages
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Personal Web Pages
  4. HTML Tutorials
  5. Includes Make Changes Easy - Includes are Simple Code That Saves Time and Effort>

©2009 About.com, a part of The New York Times Company.

All rights reserved.