Last Updated on April 20, 2020

affiliate shopIf you ever tried affiliate marketing, probably you’ve noticed that some merchants offer data feeds for their affiliates.

What is a data feed?

A data feed is a txt or csv (comma separated values) file which can be imported into a MYSQL database, from where you can display its content on your website. The file contains the products to be sold, accompanied by info such as picture, description, size, price…

The big advantage of a data feed is that you can have the offers on your site updated, by simply importing the data feed in your database, and overwriting the existing recordings.

You can links such feeds to your WordPress blog, with the purpose to create separate store pages for your visitors. Steps to be followed:

1. Create a new table (yournewtablename) into your WordPress database, using the phpMyAdmin facility (all major hosting companies offer this). The number and names of the fields should match the ones provided by your merchant (usually, the first line in the data feed contains the field names, or the merchant provides you with a feed preview, where you can see them).

2. Define a new page template in your WordPress theme.

  • Using a ftp program, download the default page template, then open the file with a text editor (avoid Microsoft Word, because it sometimes introduces some additional characters which make the page not work).
  • Rename the file in such a way that you’ll know this is your store page template.

3. Replace the new template’s content with this new one:

<?php get_header(); ?>
<h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
Some introductory text for your online shop

Template Name: YourNewTemplateName


$dbhost = '';
$dbuser = 'yourusername';
$dbpass = 'yourpassword';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'yourusername';

// Formulate Query
// This is the best way to perform a SQL query
// For more examples, see mysql_real_escape_string()
$query = sprintf("SELECT * FROM yournewtablename");

// Perform Query
$result = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;

echo "<br />";
echo "<table border='0'>";
echo "<tr> <th align='center'>Photo</th><th>Article</th><th align='center'>Description</th><th align='center'>Price (USD)</th> </tr>";
// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
while ($row = mysql_fetch_assoc($result))
echo "<tr><td>";
echo "<a href=\"" .$row['Link'] . "\">
<img src=\"" . $row['Thumbnail'] . "\" border=0 alt=\"" . $row["Thumbnail"] . "\">
echo "</td><td align='center'>";
echo $row['Name'];
echo "</td><td align='center'>";
echo $row['Description'];
echo "</td><td align='center'>";
echo $row['RetailPrice'];
echo "</td></tr>";

echo "</table>";

// Free the resources associated with the result set
// This is done automatically at the end of the script

<?php get_footer() ?>

You’ll have to replace all italic things with your details (yournewtablename, yourusername, yourpassword…)

4. Upload the new template to the server, in the same location with your the files of your current theme.

5. Login to your WordPress admin pannel and write a new page.

6. Write the desired title of the page, then go to Page Template (on the right side of your screen) and select yournewtemplatename. You don’t need to write anything on the page, because it won’t appear anyway. The content is already included in the template.

7. Publish your page.

If you are not happy with the layout, you can play around with CSS divs until you get what you like. If you want to see such an affiliate shop in action, you can check out this Baby & Children Personalized Gifts Shop.


  • In the data feed file, you will need to manually insert your affiliate ID (at least the ine I’ve used for this tutorial purpose contained a generic YOURAFFILIATEID string, which I replaced with my Shareasale affiliate ID). You will have to use the Find & Replace command in your text editor. If you forget this, your affiliate shop won’t bring you any money.
  • In case of very large datafeeds, with thousands of products, you’ll have to modify the script in such a way that you either publish the content on several pages, or give a selection (or search) possibility. Otherwise, your page will take forever to load.

In this way, you can append affiliate stores to your blog. If you want to try it and you need assistance, you can ask me for help any time. For free ๐Ÿ˜‰