Using Data feeds in wordpress are the best way to build an affiliate web site. Me like everybody had to go through with the pains of creating affiliate links manually for each and every merchant/product. It is a tedious task to build affiliate links this way. Well, if you have the time and energy to build your affiliate online store by manually creating those links, good for you. But why to take the trouble when there is a way to automate your wordpress posts with tons of product links from various merchants. It sounds interesting right? Of course i was excited when i heard about data feeds. With the power of wordpress and php put together, i know it should be possible. Thanks to some googling around and i was able to read some articles and ideas on implementing data feeds in wordpress. There are also some services trying to make some money on implementing affiliate data feeds in wordpress, but i was somehow desperate to find a solution myself. Since there are lot many free data feeds available from various merchants and affiliate networks, i felt like implementing these feeds myself. Finally, when i was able to get it right, it became just a breeze to build an affiliate store using data feeds in wordpress. I’ll give some insight and details on all the free data feeds available from merchants in a different post, but for now, let us get into the fire drill (not actually) of converting data feeds into web pages using the wordpress platform.
Importing data feeds into your mysql database
——————————————————–
Some Assumptions:
- You should have already downloaded the data feed file from your affiliate merchant and you know the web path or URL of the file.
- You will also need to add a MySQL database on your server, create a user with full privileges and add the user to the database.
Following is the working code that I’ve actually used and finally came up with a post for the merchant JeGem (Commission Junction Network). If you want to take a look, click the links below.
I’ll explain “creating a wordpress post after importing data feeds into your database”, as a separate post (Part II) as the importing code alone is going to take some space and it also lets you to concentrate one step at a time. So, here we go. For better viewing, I’ve highlighted the code in blue color. Comments are placed in the code wherever necessary. If you are confused or have questions, you can always ask me with your questions as comments.
————————————————————————————-<?
$dbh=mysql_connect (”localhost”, “<user>”, “<password>”) or die (’I cannot connect to the database because: ‘ . mysql_error());
mysql_select_db (”<database>”);
// File can be anywhere on the Internet. Fill the ??? spot with the right URL. You can basically download the merchant feed into
// your web site and give your appropriate URL
$FeedFile = ‘http://???/jegem.txt’;
//jegem_temp is the table name
mysql_query(”drop table jegem_temp”);
mysql_query(”CREATE TABLE jegem_temp (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id),
Name varchar(100) NOT NULL default ”,
Manufacturer blob NOT NULL,
Description blob NOT NULL,
longdescription blob NOT NULL,
Sku varchar(50) NOT NULL default ”,
SalePrice varchar(7) NOT NULL default ‘0.00′,
Price varchar(7) NOT NULL default ‘0.00′,
LinkURL blob NOT NULL,
ImageURL blob NOT NULL,
Category varchar(100) NOT NULL default ”)”) or die(mysql_error());
// fopen fclose is exchangeable with fzopen fzclose which would open GZIP files instead of text ones.
$feed = fopen($FeedFile, ‘r’);
$rowNum = 0;
$recCount = 0;
while($data = fgetcsv($feed, 3000, “\t”)){
if($rowNum > 0){
$iName = addslashes($data[3]);
$iManufacturer = addslashes($data[9]);
$iDescription = addslashes($data[2]);
$ilongDescription = addslashes($data[11]);
$iSku = addslashes($data[0]);
$iSalePrice = addslashes($data[5]);
$iPrice = addslashes($data[4]);
$iLinkURL = addslashes($data[1]);
$iImageURL = addslashes($data[7]);
$iCategory = addslashes($data[8]);
$sql = mysql_query(”insert into jegem_temp (Name, Manufacturer, Description, longdescription, Sku, SalePrice, Price, LinkURL, ImageURL, Category) values (’$iName’, ‘$iManufacturer’, ‘$iDescription’, ‘$ilongDescription’, ‘$iSku’, ‘$iSalePrice’, ‘$iPrice’, ‘$iLinkURL’, ’$iImageURL’, ‘$iCategory’)”) or die(mysql_error());
$recCount++;
}
$rowNum++;
}
// be careful and give your correct commission junction pid as this is the ultimate key step to earn commission from sales
mysql_query(”update jegem_temp set LinkURL = replace(LinkURL,’xxxxxx’,'<your_cj_pid>’)”) or die(mysql_error());
mysql_query(”OPTIMIZE TABLE jegem_temp”) or die(mysql_error());
mysql_query(”drop table jegem”);
mysql_query(”ALTER TABLE jegem_temp RENAME jegem”) or die(mysql_error());
$to = “<your_email>”;
$subj = “Commission Junction Database Table jegem Update Report”;
$mssg = “This is an automated email. The CJ Table update has completed successfully.\n\nThe total number or items loaded was
$recCount.\n\n”;
$hdrs = “From: $to\n”;
mail($to, $subj, $mssg, $hdrs);
fclose ($feed);
echo “CJ’s Merchant JeGem Import Completed Successfully”; ?>
————————————————————————————-
Notes :
- Save the above code and call it Import_JeGem.php (well any name that you can think of).
- FTP the file to your desired folder of your site. In fact create a Datafeed folder under your wordpress directory for better folder maintenance.
- Run the code with the correct URL path. If you have ftp’ed the file to the Datafeed directory as mentioned in the above step, your path should be
http://www.<yoursite>.com/wordpress/Datafeed/Import_JeGem.php - PHP is case sensitive. So make sure your url is entered with the right cases.
- After running your import page, you should see a “CJ’s Merchant JeGem Import Completed Successfully” message on the web page, which indicates your datafeed import is successful.
- You should also get an e-mail to the e-mail address you specified in the code above.
- What should i say here, hmmmm you should take a breather now :-)
That is all it takes to get your affiliate feeds into mysql database and you can control your presentation in however ways you want. You can have lots of posts for the merchant with various product categories. All this, I’ll explain in my next post on how to post the datafeed in wordpress for the world to see.
I hope you enjoyed reading this post and it was also helpful. Stay tuned for more ideas and tips on data feeds. Until then, wish you good look and success in your affiliate marketing.









: Get Instant (
) Updates









Be The First To Comment
Related Post
Please Leave Your Comments Below