How To Make An Affiliate Shop Using Data Feeds In WordPress

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 😉


  1. Hey Lutfi, thanks for stopping by. If you open the datafeed file, you will notice that it has column headers. Those headers will be your table’s fields. I’m going to write another post for you, because it would be too much to include it in a comment. If you still cannot manage to do it, make sure you come back here in about one week (I don’t know if I can write the detailed post earlier).

  2. Oh, i m forget that tool have demo version.This version that i have used. But in your article will show link like “This product was imported with the WordPress Datafeed Import script”.

    And the trick is export your data to XML (wordpress admin > manage > export). With your text editor find and replace the link :D. Simple right?

    If you don’t mind, you can email me if you have another great tool information. Thanks

  3. Lutfi, you don’t have to use the WordPress import tool. You use phpMyAdmin, which comes with your hosting (most of the times), and that has an import option you will use. Before doing that, you’ll have to open your datafeed file in a text editor and place there your affiliate ID code, using find and replace. I’ll mail you next week.

  4. Simone: Very interesting. Would it be difficult to set this up to post one product per post per day or so…a variable schedule would be best. Also if this is possible, how much would you charge to write the script for me? Feel free to email me if you like.

  5. Hi Simonne

    Thanks for your post! Is exactly what I need for the moment..
    Have a questions and I very appreciate if you have time to reply.

    How can populate that database table with informations delivered in data feeds ?

    If I understand from your post you described method to create a table in WordPress database and an way to extract and display informations.. but how can fill that table ?

    PS: sorry if my questions is naive but I’m new in that domain.


  6. Hi Simonne
    Thanks for your reply !! very fast..

    Solution is simply and clever.
    That mean must create my table in conformity with field from data feed delivered by merchant.

    But what happened if a merchant change anything? Price, quantity, etc.

    Is a option to make the process automatic? A cron job or anything else..?


  7. Hi Doru, after you create your table and put your affiliate id in the datafeed file, go to phpmyadmin dashboard, select your table, then use the Import function (it is one of the tabs in the upper menu). Then you use the Browse function to select the datafeed file, and at the Format of imported file usually it works with SQL. If it is not working for you, try also CSV and see what happens.

  8. Yes, you can set up a cron job and some script to insert your affiliate ID in the datafeed. Unfortunately, setting up cron jobs is not my hardest point, so I can’t help you too much. Actually I don’t care too much if the merchant changes anything, because when a visitor clicks on the links, he is redirected to the merchant’s site, and he can look in there for whatever he wants. I still get the commission, because he entered the site from my affiliate link.

  9. I just did a search for “affiliate merchant datafeeds” and came across your blog post here…

    I have a few questions when you get a chance please…

    1) Is what you are showing here the exact same thing this guy is charging $154.00 for? (I’m not affiliated in anyway with that website)

    2) Is there anything in your instructions above that differs when using WordPress 2.5?

    3) Will data feed fed sites like these have legs? Meaning, will they continue to rank well with search engines, or will they be dropped by Google when Google starts seeing them as spammy just like they did with those made only for Adsense sites?

    Thanks very much!

  10. Yes, beauty blog, you can tweak your layout as you wish, but you need to know some HTML. If you look into my code, you’ll see the layout is based on a table. Just change the table and you’re done.

  11. Hey Steve,

    I don’t know what that guy uses, but it is probably something similar. Datafeed sites are ok, but you have to provide additional content on them, because the same feed you use is simultaneously used by thousands of other affiliates out there. You have to be unique. As of the sales that guy claims to make with his shop, I don’t believe a single word. I have lots of online stores, well researched and with good keywords, and I’m far from making that kind of money from them. If you want a free script for importing datafeeds, check out – they have a good solution for online stores.

  12. Steve, I forgot: there should be no difference in WP 2.5, because the code has to do with php and mysql, and not with the WordPress functions and stuff. It is just a simple query of the database which contains the affiliate feed.

  13. Thank you very much for your response!

    Actually, the guy (Neal Shearing) is a good guy but that $4000.00 in sales was gross sales. His affiliate commissions were only about $95.00. Still, not bad for its first month, if you had a bunch of those up. I wonder how much it has made since then because its not on the first page of Google anymore.

    Thanks again!

  14. OK, Steve, that makes sense. Of course it’s not bad, and if you can set the stores and then spend very little time on maintenance, this can be a good business model.

  15. Hi Simonne, thank you for such a wonderful post! I managed to get it working on my new site and it’s wonderful! I investigated several solutions and they either didn’t do what I wanted or were too expensive. However after a few hours of trial and error I have successfully got it working as being an Oracle person I had to learn the MySQL side of creating and loading tables etc. Thanks again! 🙂

  16. hi.. this is my 1st visit.. great post.. hope i will read more about data feed. or maybe you can detail it more because a newbie like me didn’t fully understand . i have a shareasale account but not making any money. i hope with your info i can make some money..

  17. Hello Simonne,

    I want to start blogging and create a shop on my wordpress blog. I’m totally new but I learned html and css a year ago.

    If I will start a wordpress blog this time and set up a shop on my blog, are the info you posted here still applicable at this time? I asked it since I noticed your article was posted two years ago.

  18. Hi Maria,

    Yes, the info is still valid. It’s only my example blog is not working anymore. Additionally, you can check out – they have a free program that imports feeds – you can build nice shops based on that.

  19. Thanks a lot for your response, Simonne. I’ll be looking for and working for a blog
    shop soon and will give you feedback on how helpful
    your article is once I apply them.


  20. Hi Nice post, some good work there, I started off like you trying to write a script so that I could use datafeeds in wordpress. I went down the plugin route though and now have created a plugin that I sell. I can send you a copy if you would post a review of it.


    I am about to launch a new website and a new version of the plugin so your feedback would be welcome.

  21. What a genuinely helpful post! Datafeeds are a great way to set up a store but like everything can take some work in the longer term. We also ended up engineering a solution which turned into a plugin for managing csv files.

    Simonne, if it’s ok I’ll send you an email so you can review?

  22. Yes, this is how you do it. However, this is an old article. By now, you can already use WordPress themes that include commerce functions. There are even some good, free ones out there. Check out Woo Themes, for instance.

Comments are closed.