iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register

Go Back   WebForumz.com > Resources > FAQ > PHP
Register All Albums Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read

Author


karinne
Karinne Legault is a Programmer Analyst working in Federal Government in Canada now working on .NET projects which she is still trying to get to grips with.

Her passion however is Web Design where she has 10 years experience. In the early years, just getting to grips with the movement of Web Standards being an integral part of the services she offers. You can view her portfolio site at KarinneLegault.com

RSS Feed

Your Options
I have many pages for my website and when I add a menu item, I am stuck changing it on every pages! Is there an easier way?

Why bother changing the menu on every single page on your website? just use a simple PHP include function for a quick answer.

It's high time you jump on the "includes" band-wagon! You're missing out on something so easy and simple to implement that could have saved you from replacing that "one word" in your menu on 20 different pages!!

The best option is to use the PHP include() function. It's so simple to implement, you will be hitting yourself for not asking earlier.

The Syntax


<?php include('directory/file.php'); ?>

How to use it

Here's your index.php file (note that all your files using the php include() function must have the .php extension)


...
<body>
<?php include('navigation.inc'); ?>
<div id="content">....</div>
</body>

And this would be your navigation.inc file (note that your included file can have the extension you want – .html, .php, .inc, .whatever)


<ul>
<li><a href="home.php">Home</a></li>
<li><a href="services.php">Services</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>

There's is also the SSI version (Server-Side Includes). It is also the same syntax for ASP includes

The Syntax

Using a virtual path (most commonly used)


<!––#include virtual="/directory/page.html" ––>

Using a relative path


<!––#include file="page.html" ––>

How to use

Here's your index.shtml or index.asp file (note that all your files using the SSI or ASP include function must have either the .shtml or .asp extension)


...
<body>
<!––#include virtual="/navigation.inc" ––>
<div id="content">....</div>
</body>

And this would be your navigation.inc file (note that your included file can have the extension you want - .html, .asp, .inc, .whatever)


<ul>
<li><a href="home.shtml">Home</a></li>
<li><a href="services.shtml">Services<</a></li>
<li><a href="contact.shtml">Contact</a></li>
</ul>

Related Resources

Members's Comments No Comments. Be the first to comment on and rate this resource.


Search Engine Optimization by vBSEO 3.2.0 RC8