Site Owners Forums - Webmaster Forums

Site Owners Forums - Webmaster Forums (http://siteownersforums.com/index.php)
-   Programming General (http://siteownersforums.com/forumdisplay.php?f=44)
-   -   Save time using the PHP include Function <?php include (http://siteownersforums.com/showthread.php?t=57020)

leox123 05-10-2012 11:56 AM

Save time using the PHP include Function <?php include
 
One of the main problems faced by webmasters is saving time when it comes to creating websites. When starting a website, one may choose to create a navigation menu like the following to link to each page:

Which looks like: Home About UsLinks Contact Us

So now, you have your 4 pages - and all is well. But, as the site expands you need to integrate a forum - which leaves you with 4 pages to update. No problem at all... But supposing the site had 100+ pages! That would be a very monotonous time consuming job.

This is where we bring in the php include command to really speed things up!

Create just the navigation menu on its own, and rename all of your pages to .php

In this case, the navigation menu will look like this:

Quote:

Home -

About Us -

Links -

Contact Us
Which looks like: HomeAbout UsLinksContact Us

Save this file as "menu.inc" as we will be including it elsewhere - hence the .inc extension.

Now, open up your .php pages that the menu links to, and simply add the following code at the very top, to include the navigational menu on the pages:



The code is telling the php page, to "include" the menu.inc file - and it does!

Once this has been added, any changes in the menu.inc file are reflected across the whole site making updating a lot easier!

Why stop at menus? This can be utilised for adverts, footers, headers, templates and much much more!
Back to top

isoconsultantgm 05-17-2012 11:20 PM

very nice post thanks for sharing this valuable information.


All times are GMT -7. The time now is 01:13 AM.


Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.