Integrating Datafeed Studio with WordPress

Update : This post is really old now – and even though the information below will still work, the far easier way is to use the WordPress plugin that Datafeed Studio now comes with, which allows you add a price compare box to your WordPress posts or pages as simply as writing :

[ds query='pleo']

anywhere within the page/post content.

Sometimes you may want to access product information contained within your affiliate datafeeds outside of a Datafeed Studio created site, e.g. inside a WordPress blog.

This post will show you how to easily achieve this if your WordPress site (or similar) resides on the same physical server as your Datafeed Studio installation. To illustrate what is possible I’ve quickly created a new WordPress site for the Pleo Toy. This WordPress theme has three columns.

The middle column is the one we are interested in – it shows all the current prices and retailers of the Pleo according to the data held in our Datafeed Studio installation.

pleoprices.gif

How does this work?

Well, as our site is on the same server as Datafeed Studio we just hook into the datafeed functions with the following few lines of code :

<?php

$DS_LIB= ‘/home/martinwood/src/php/datafeed_studio/lib’;

$PUBLIC_URL = ‘http://dealdrop.co.uk’;

require “$DS_LIB/database.inc”;

require “$DS_LIB/functions.inc”;

$products = get_products($db, “select * from products where (match(name) against (‘+pleo’ in boolean m
ode)) order by merchant_name limit 50″);

foreach ($products as $product) {

echo <<<EOHTML

<li><a target=”_blank” href=”{$PUBLIC_URL}/{$product['deep_link']}”>£{$product['display_price']}
@ {$product['merchant_name']}</a></li>

EOHTML;

}

?>

Just paste these into the appropriate file of your WordPress theme and you can get a similar list of product prices, such as these Pleo Prices embedded in your blog or web site.

Neat, huh?

All you need to change above is :

$DS_LIB – the path to the Datafeed Studio installation “lib” folder on your server

$PUBLIC_URL – the main URL of your public Datafeed Studio site

and, of course, you want to change the product name to be something other than ‘pleo’ in the line containing the “get_products” function call :-)

That’s it.

A future article will show a similar method integrating with WordPress custom fields to dynamically do a product price compare within WordPress.

4 Comments so far