We’ve had several questions lately about how you can use PHP includes in your datafeed web service client to do things like add standard site-wide content to your datafeed template.
Note: Due to some recent changes in the way the datafeed client creates SEO friendly URLs, we’ve changed the main datafeed client script name from “shop” to “shop.php”. To cover both versions we’ll refer to this script as “shop” or “shop.php” below.
Here’s how you can accomplish this:
- Look for your “shop” or “shop.php” script which is in the same folder as the “template.html” file.
- Make a backup of both the “shop” or “shop.php” script and the “template.html” file just in case you want to revert back to the original.
- Open the “shop” or “shop.php” file up in a text editor and add the following right below the opening <?php code:
ob_start(); include(’/path_to_include/include.php’); // Replace with actual path and file name. $my_include_content = ob_get_contents(); ob_end_clean();
- Look for the block of code that looks like this:
$strHTML = eregi_replace(’\[PAGE_TITLE\]‘, $page_title, $strHTML); $strHTML = eregi_replace(’\[PAGE_KEYWORDS\]‘, $page_keywords, $strHTML); $strHTML = eregi_replace(’\[PAGE_DESCRIPTION\]‘, $page_description, $strHTML); $strHTML = eregi_replace(’\[PAGE_NAVIGATION\]‘, $page_navigation, $strHTML); $strHTML = eregi_replace(’\[PAGE_CONTENT\]‘, $page_content, $strHTML); $strHTML = eregi_replace(’\[HIT_TRACKING\]‘, $hit_tracking, $strHTML);
- Add the following line right below that block of code:
$strHTML = eregi_replace(’\[MY_INCLUDE_CONTENT\]‘, $my_include_content, $strHTML);
- Save your “shop” or “shop.php” script.
- Open up your “template.html” file and add [MY_INCLUDE_CONTENT] to the html where you want that content to show.
- Save your template.html file.
- Upload your files to your server.
- If this isn’t the first time you’ve uploaded changes and/or viewed your datafeed pages make sure you clear your cache by logging into your account and going to ‘Tools -> Edit Current Datafeeds’ and then click on the ‘Clear Page Cache’ link next to your datafeed subscription in the list.
** These instructions assume that your PHP include just echo’s out a block of html content. If your include script places your html content within PHP variables then all you would need to do is simply include your script from within the “shop” or “shop.php” file, add eregi_replace() function calls (See example above) for each of the variables you want to use from within your include script, and then add those place holders (eg. [MY_PLACE_HOLDER]) to your template.html file.
Scott & AvantLink


1JT VonLunen on Feb 21, 2008 at 3:15 pm:
Thanks for the quick response on this Scott. The first few lines of code are key.
I had to reset the “include_path” right before my include call to get the correct file name because the .php file I using also has additional includes in the code. I kept getting an error that the directory or files don’t exist at “include_path”= /mysite/avant_includes. Here’s an example of what I was able to accomplish(thanks to scott’s help): http://www.nationaloutdoors.net/bc/shop.php/D-1/CampHike.html. You can see recent posts (my content) at the bottom of the page.
2support on Feb 21, 2008 at 3:35 pm:
That’s looking great JT. Your implementation is an excellent example of what can be accomplished using this tool.
Scott
3BJ Baker on Feb 24, 2008 at 5:41 pm:
How do you reset the “include_path”
4support on Feb 25, 2008 at 8:53 am:
You can use code similar to the following to reset the include_path variable from within a script:
$new_path = ‘Whatever additional path you want to include from’;
$current_path = ini_get(”include_path”);
ini_set(”include_path”, “$current_path:” . $new_path);
-David