Mar 06 0comments

Lots of people use wordpress, textpattern and other similar CMS / Blog type systems for their sites these days, and you can always find plugins that will make it easy to add content or ads that are easily changed. However, these programs don’t fit every site and sometimes you need a bit of functionality that’s not available via a plug-in.

Here is where including php files in your html can make your life a lot easier. For example, we’re currently working on putting Easy By Design together. If you take a look at the page, you’ll see on every page we have 5 tag lines about the product near the top of the page and a section for “Recent Work” near the bottom. Once the advertising wheels start grinding we’ll have to update that recent work semi-frequently and we may want to try out different taglines. However, these items are on every single page of the site and the last thing I want to do is manually update every page when we want to change something. Here’s where PHP helps us out.

I’ve used a include command to call the 5 tag lines and the recent work area of the site from a php file on my server. So now I just have to change that one file and the information will update on every page. Brilliant!

There’s all sorts of handy uses for this little hack, from ad code implementation (so you can easily try different colors and types of ads) to increasing the value in a sale because someone can easily change the ad code on the 1000 page site you have from one file.
Here’s how it’s done:

First, create a .php file somewhere on your site and stick the code you want to insert on multiple pages into this file. (Don’t use head or body tags or anything like that, unless you are making a header file. Just put in the code exactly as you want it to appear in the files you will include it in).

Then load up the page(s) where you want this file to include and insert the php code:

include(”http://www.adomain.com/pathtofile/filename.php”);

If you are modifying a .html document you will need to implement the code as follows:

< ? PHP include("http://www.adomain.com/pathtofile/filename.php"); ? >
(Without the spaces in the opening and closing tags)

Your server must also be set to “parse html files as php”, if you want to include files in html documents. This is a relatively easy change to make, just ask your host for help with setting it up.

There you have it, a simple little snippet of code really can make your life a lot easier :)

Like this post? Share it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Technorati
  • StumbleUpon
  • Reddit

Leave a Reply