How To Add Affiliate Products From LinkShare

by derek on January 22, 2009 · 46 comments

In this next step of our case study on getting started with affiliate marketing, we will examine how to automate the process of adding affiliate products from LinkShare to our site.

Merchandiser Data Feed Program

LinkShare offers a service that they refer to as the Merchandiser Data Feed Program that allows publishers to maintain a database of product links that is updated daily. Unfortunately, there is a one-time setup fee of $250 unless specific criteria has been satisfied.

Since we are hoping to get started with as little upfront cost as possible, this is probably not our best option and is one that I have not personally explored. However, there is another option for those of us that do not meet the criteria to avoid the setup fee.

Merchandiser Query Tool API

Before you get scared by the mention of API, let me tell you that this is extremely easy to implement and does not require extensive technical knowledge when you use the process that I am about to share with you.

The Merchandiser Query Tool API is a Web service that allows you to run a query against any one, or all, of the merchants that you have a partnership with at LinkShare and will return a listing of affiliate products. The query can return a maximum of 4,020 search results, which should be more than sufficient for our needs.

So how do we leverage this service?

In order to efficiently use this service, we are going to create a custom script (fancy word for PHP page) that we can use throughout our site to display relevant affiliate products.

There are a few prerequisites that must be met in order to use this script: 1) we have an account at LinkShare.com and have been approved for at least one merchant; 2) we have requested and received our web services token from LinkShare.

Creating Custom LinkShare Script

Now that we have satisfied the prerequisites, we are ready to create our script. Don’t worry, it really isn’t as bad as it sounds. To get our script working on our site, we need to perform the following steps.

  • Save the code from Code Example #1 to a file named linkshare.php
  • Open the file in a text editor and insert our LinkShare token on Line 4
  • Upload the file to our web host

Now, wasn’t that easy?

At this point, we have a functioning custom script on our site that will return affiliate products from our merchants at LinkShare. To test that our script is working, simply open a new browser or tab and navigate to the following URL:

1
http://yourdomainname.com/linkshare.php?keyword=yourkeyword

Be sure to actually update the link to include the appropriate domain name and a relevant keyword for at least one merchant. If everything is setup properly, we should see a display of products from at least one of our merchants.

There is the possibility that we will see a message that there aren’t any available products. That doesn’t mean that the script is not working, as we may simply need to change the keyword to match the products of our approved merchants.

Also, this script assumes that our web host supports PHP5 as the call to simplexml_load_file will not work if your host is running PHP4. If you encounter this problem, let me know and I can share the code to work around that issue.

One last note about the code example, you will note that there is a URL on Line 2 that has been commented out. For whatever reason, I found the standard LinkShare link to be extremely unreliable and often resulted in a script failure. By changing to the URL on Line 3, I have not had any problems but feel free to experiment with either URL.

Code Example #1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?
  //$url = "http://feed.linksynergy.com/productsearch";
  $url = "http://65.245.193.50/productsearch";
  $token = "ADDTOKENHERE";  // Add your LinkShare token here
 
  $results = '';
  $resturl = $url."?"."token=".$token;
 
  if (isset($_GET["keyword"]))
  {
  	$keyword = $_GET["keyword"];
  	$resturl .= "&keyword=".$keyword;
  }
 
  if (isset($_GET["cat"]))
  {
  	$category = $_GET["cat"];
  	$resturl .= "&cat=".$category;
  }
 
  if (isset($_GET["max"]))
  {
  	$maxresults = $_GET["max"];
  	$resturl .= "&max=".$maxresults;
  }
 
  if (isset($_GET["mid"]))
  {
  	$mid = $_GET["mid"];
  	$resturl .= "&mid=".$mid;
  }
 
  $SafeQuery = urlencode($resturl);
  $xml = simplexml_load_file($SafeQuery);
 
  if ($xml)
  {
    foreach ($xml as $item) {
        $link  = $item->linkurl;
        $title = $item->productname;
        $imgURL = $item->imageurl;
        $price = $item->price;
        $merchantname = $item->merchantname;
        $description = $item->description->short;
 
        if($link != "")
	        $results .="<div id=\"product\">
	        		<div id=\"product_img\"><a href=\"$link\"><img border=\"0\" src=\"$imgURL\"/></a></div>
	        		<div id=\"product_link\"><a href=\"$link\">$title</a></div>
	        		<div id=\"product_desc\">".$description."</div>
	        		<div id=\"product_price\">Add to Cart: <a href=\"$link\">$price</a></div>
	        		</div>";
	}
  }
 
  if ($results == '') { $results = "<div id=\"product\">There are no available products at this time.</div>"; }
 
  print $results;
?>

Now that we have our custom script installed on the server and everything is working great, we need to investigate how we can actually implement this script on our site.

Implementing Custom LinkShare Script

Ideally, we will want to incorporate one or more affiliate products within the content of a blog post. As an example of what we want to accomplish, look at how the affiliate products are integrated in this post about buying the right football gloves.

In order to implement the script in the manner described here, our site will need to satisfy the following prerequisites: 1) Exec-PHP plugin must be installed, as we will be executing PHP code within a blog post 2) our web host must support cURL (if not, there is a workaround).

Next, we simply need to copy the code from Code Example #2 into our blog post and update the URL parameters as necessary. There are four parameters that we can specify:

  • keyword :: Replace KEYWORD with the keyword that you would like to use for your product search
  • cat :: Replace CATEGORY with a product category to restrict the search results
  • max :: Replace MAX with the maximum number of products to return in the search results
  • mid :: Replace MERCHANT with the merchant id of an advertiser to limit the search results to their products only

Of the four parameters above, only the keyword is required. The remaining parameters are optional, although they will assist in refining our search results so the products match the content of our post as closely as possible.

Note: If you choose not to use one of the optional parameters, remove the entire parameter (i.e. remove “&mid=MERCHANT” not just “MERCHANT” if you choose not to specify a merchant).

To receive the best quality search results, it may be necessary to experiment with a variety of parameter settings.

Code Example #2

1
2
3
4
5
6
7
8
9
<?php
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, "http://" . $_SERVER['SERVER_NAME'] . "/linkshare.php?keyword=KEYWORD&cat=CATEGORY&max=MAX&mid=MERCHANT");
curl_setopt($cURL, CURLOPT_HEADER, 0);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
$strPage = curl_exec($cURL);
curl_close($cURL);
echo($strPage);
?>

At this point we should have our custom script installed on the server and have a new blog post that is returning relevant affiliate products within the content of the post.

Wrapping It Up

The process above is exactly what I have done to integrate affiliate products on both Pro Football Workouts and Chicago Football Gifts. Keep in mind that the code provided above does not include any true error handling, but it has been working well on my sites.

Also, as mentioned earlier, you may encounter problems depending on certain configurations made by your web host. The two most likely issues will be support of PHP5 and/or cURL. If you encounter problems with either of these, let me know and I can offer assistance.

Is this a perfect process?

Not by any means, as there is still a good deal of manual work involved and the code could certainly be improved upon (adding robust paging controls, error handling, etc.). This should get you started though and allow you to start adding affiliate products from LinkShare.

Now go earn some money!


Stay In The Loop!

Subscribe to the Derek Semmler dot com feed via RSS or Email to receive notifications when new posts are published. Follow the WordPress ninja on Twitter too!

{ 44 comments… read them below or add one }

ohn from JHome Furniture January 23, 2009 at 1:01 am

At the start of the post, I must admit that this could be very technical and I may not be able to do it on my own. But your explanations really cleared up some things for me. Maybe, when I find the time, I might put this into action.

Reply

derek January 24, 2009 at 11:43 am

John, it really isn’t too bad but I understand that the technical aspect might make a lot of people shy away. If you have questions, be sure to let me know.

Reply

Writers For Jobs- Make $200-$300 Daily February 25, 2009 at 12:33 pm

I really cannot stand Linkshare to be quite honest with you. But you did write a pretty good comprehensive DIY guide for adding products. I wish Linkshare had a more easier interface to navigate.

Reply

Kelvin Kao January 23, 2009 at 1:44 am

Good to see a detailed example like this. Most websites I’ve seen just say you should do this and this but never elaborates on how, but you do. Now, I’m not going to be doing anything with affiliate products any time soon, so I don’t really give a damn in that aspect, but it’s fun for me to read about this kind of stuff because I like to know how things work… that and I’m a programmer.

I wonder if that’s a static address though. What if their IP changes?

For anyone with any php knowledge, this is pretty sraight-forward code to read. For people not familiar with php, it’s still simple in that they can just plug in the token and go.

Nice post!

Kelvin Kaos last blog post..WordGirl: My New Favorite PBS Show

Reply

derek January 24, 2009 at 11:47 am

Thanks Kelvin! This post was actually a lot of fun to write as I love digging into the technical things and trying to explain that in a way that will help other people.

I was trying to decide how much detail to give about the entire code block and hope that I provided enough without losing people.

Re: the IP, I haven’t had any issues with it and have been using it for quite some time. That also means that I haven’t reverted back and tried their domain name either. This has been one of those “if it ain’t broke, don’t fix it” thinks for me.

Reply

trendy January 23, 2009 at 6:02 am

that was great examples really .. i visited several sited , blogs but nobody have time to explain the things, they usually put a short code for any task and they dont worry that it is understandable by others or not..
but you really did a great job…

Reply

derek January 24, 2009 at 11:48 am

Glad to hear that you liked it and hopefully you will find it useful. Thanks for stopping by!

Reply

Ling from Uptake January 23, 2009 at 8:17 am

My eyes started glazing over halfway through, so you’ll have to forgive me for that. One question, though. This script is limited to this particular network, I assume. So what about the others (if there are others)? Isn’t tthere some kind of script which can pull in data from all the major aff. networks?

Reply

derek January 24, 2009 at 11:50 am

Ling, you’re right in that this is only for LinkShare. I’ve got a separate script for Share-a-Sale as the process is different for me. There is no question that these could be combined into one script, which is what many of the tools have done for you.

The problem with making one script of your own is that each network, as well as each feed, is different enough that it can quickly become unmanageable.

Reply

Nicole Price January 23, 2009 at 8:36 am

It is all over my head Derek. I doubt that I can do what you expect me to do in your last paragraph. I like your style though!

Reply

derek January 24, 2009 at 11:51 am

It never hurts to try. :)

Reply

Nick from romandock dot com January 23, 2009 at 8:47 pm

Sweet! I’ve already copied the code so I can use it, but now I have to figure out if I already have a LinkShare account or if I still need to create one. Oh, and I already copied your code so even if you take it down, it’s too late :)

Nicks last blog post..Make PDF Files With PDFCreator

Reply

derek January 24, 2009 at 11:52 am

Lol, you can be pretty certain that this code will be here as long as this blog exists. ;)

Let me know if you have any questions, as well as if you are able to make any use out of this code.

Reply

Gabe January 24, 2009 at 4:05 pm

It is really the technical side of it, as you are saying derek, that scares people off! The information is nice, but I am having difficulties to understand the codes!

Reply

Neil from PS3 January 24, 2009 at 4:46 pm

I tried to use Linkshare on one of my previous ventures and couldn’t really make it pay. I have been building my traffic to my current blog and have been getting plenty of click throughs to amazon so hopefully will get some conversions and make some money. Then I might have a look into some other advertisers.

As I already have a linkshare account then I will probably use them so these tips will come in very handy when i get around to it.

Currently busy writing articles for my blog and redesigning one of my sites from scratch. New Design, New Content, New Host, Everything

Reply

45 Second News January 25, 2009 at 5:29 pm

Man this looks hard. Its gonna take quite a while to figure this out.

45 Second Newss last blog post..Israeli’s Accused Of War Crimes

Reply

Limoeg January 26, 2009 at 3:23 am

Thanks for the instructions.

Reply

est Man from BBest Man Speeches January 28, 2009 at 10:24 pm

That’s a good technical article. However I wasn’t not very comfortable doing this on my own. In fact adding the right affiliate product on your page from LinkShare could be tricky. Thanks for your insight.

Reply

Women's Dress Shirts January 29, 2009 at 10:32 pm

Nice post, I was looking for something like this and you’re explanation of how to do it was great. Thanks again!

Reply

amrita from Web Site Design Dubai January 30, 2009 at 5:45 am

thanks for such nice article this is really helpfull for my blog
thanks

Reply

David February 2, 2009 at 1:30 pm

I’m pretty new to affiliate marketing. I’ve been using Amazon, which I like because they have such a wide array of products that they can always match something to your content. I will check out this Linkshare thing though as I think it will enable me to get more targeted products on my sites.

BTW. I developed a object oriented wrapper for cURL in PHP that may be of use to you. It just makes your code neater and easier to manage. I tend to build a generic getURL( $url, $additional_opts ) for my scripts, so I just need to call a function to get a url. You can find the class here with some instructions.

Davids last blog post..Enableing Chinese, Arabic and Other High Unicode in WordPress Slugs

Reply

Internet Strategist February 4, 2009 at 12:43 am

Does anyone have any comments on the difference between LinkShare and ShareASale. I’m especially interested in why a merchant would use both or why those promoting affiliate programs would prefer one over the other. Do you all use both? Would you stop promoting a store that eliminated one of them? Which do you prefer? Thanks for any input.

Internet Strategists last blog post..Have a Blog? You Win By Reading This Blog Review Contest Entry on Best Blog Design!

Reply

Melaleuca Frank VanderSloot February 4, 2009 at 11:06 pm

One must know HTML or coding for doing such thing. I can’t do that.

Reply

Justin from Airsoft Guns February 9, 2009 at 5:39 am

That seems kind of complicated to me, but if I really wanted to, I’m sure I could figure it out. I’d rather just stick with Amazon than messing with all that code, though, although I have to admit I have derived pleasure from coding in the past.

Reply

Thomas February 12, 2009 at 11:16 pm

Thanks for the code, works great!

Thomass last blog post..Meditation classes for kids in schools

Reply

lisa February 23, 2009 at 12:52 am

wow..thanks for sharing the codes. very informative article. keep on posting.. I need that in my website… :)

Reply

Ajith Edassery | Blog Money February 23, 2009 at 4:31 am

I need to really start caching via affiliate links. So far private ad sales, adsense and once in a while referral income are the only monetization means.

Does anyone know about a good Amazon affiliate plugin?

Ajith Edassery | Blog Moneys last blog post..Google Monitor: Track your search engine ranking for FREE

Reply

Terry Walker February 27, 2009 at 7:29 am

Wow, I never knew that How To Add Affiliate Products From LinkShare. That’s pretty interesting…

Reply

Prashant June 3, 2009 at 12:30 am

I have downloaded the product datafeed XML file from my Linkshare FTP account. In this file there are limited imformation, how can i get all the information ?

Reply

Sanavas March 19, 2009 at 4:12 am

I have used linkshare earlier but I find it very difficult to make sales and dropeed it

Sanavass last blog post..Create a Blog at a Mouse Click

Reply

Karen June 8, 2009 at 9:22 pm

Thank you for this tutorial, I learned a lot!

I’d like to take the script a bit farther and develop an application that will pull products via web services.

I’m not using WordPress and I really don’t want to implement RSS for my site on a mass scale. I really need one that will allow me to compile my own data feeds since they won’t provide any unless you’re a performer or have money to invest.

Can you point me in the right direction?

~Karen

Reply

Tony June 28, 2009 at 1:39 am

Nice to see a tutorial like this on the Linkshare system, I’d love to point you at a resource that I’ve developed which is a free plugin for wordpress to show Linkshare merchandiser products within your blog.

its available here.

Linkshare Merchandiser Plugin

I hope it will be useful.
Tony´s last blog ..Meat and Cheese T-Shirts My ComLuv Profile

Reply

j henry August 11, 2009 at 8:00 pm

Great post! Keep up the good work!
j henry´s last blog ..If you want to be one… My ComLuv Profile

Reply

Guillo October 11, 2009 at 1:25 am

hey friend!

thank you for sharing your experience with us! i am very grateful.

Ont thing though… I uploaded the code in .php but when i tried it the page gave me a 401 not found error.

then i uploaded it in .htm / .html and gave me a no resilts found error with a partial code on the screen.

u can check out yourself with the test link. my domain is savingsonthefly.com

your help will be greatly appreciated!

Reply

Jon February 26, 2010 at 2:37 pm

Thank you so much, this was tremendously helpful.

Reply

Robyn March 9, 2010 at 11:33 am

Hi

thanks for this easy to understand guide. You can make use of the merchandiser for free if you’ve been a member for 3 months and have made 50 sales in the previous month – don’t quote me on the exact criteria and maybe its different for UK residents. Anywho, are you able t provide an explanation on how to use the merchandiser. I’ve downloaded the folders from the linkshare server but I don’t have a clue where to put them, what to do with them etc…

thanks for your time!

Reply

Nick April 15, 2010 at 8:39 pm

This code works great for the results I was looking for. Just one question, I have been searching all over and I am new to PHP and have some knowledge in HTML and I am looking for a way to format the results into 2 or 3 columns across instead of just the list, but I have not been able to figure out using tables with the results. Is this possible? Thanks so much for this information as it has been very helpful!

Reply

ArtMan June 12, 2010 at 12:38 am

Hi,
fantastic post and very useful. I’m tryin a couple of plugins and codes on my site. I’m looking to add the paginator, similar to what you have on your chicago footbal page. Would you mind sharing the code or instructions.
Thank you much.

Reply

derek June 13, 2010 at 11:07 am

This would probably make the most sense as a separate post to fully explain the pagination.

In a nutshell, in the Code Example #2 above I’ve added two additional parameters to the link for the current page number and the results per page. In the Code Example #1, I read in the values of these parameters and if not yet set I assign default values. In the loop of the results, I then offset the array of results according to the page number I am on and build the pagination links at the end of the loop.

I know that probably doesn’t make a ton of sense, so that is why I will provide the code and explanation in the form of a post.

Reply

ArtMan June 14, 2010 at 9:21 am

Thanks for the info. I very much look forward to your post with the code. I know a thing or two about PHP but not savy; an example code is of great help. Also the XML response does include the number of pages – is there a way to use that also as the final value?
Thanks

Reply

derek June 16, 2010 at 1:08 am

Stop on by later this morning for the pagination code. As a note, you’ll find that the main section of code was changed from the original example but I have provided the full page of code.

Hope you find it helpful.

Reply

ArtMan June 16, 2010 at 3:02 pm

Hi,
i can’t find it – I’ll check-in again later.
Thanks in advanced for all your help.

derek June 16, 2010 at 3:14 pm

Sorry, you can find the new post right here.

big24fan June 25, 2010 at 9:17 pm

I hope this thread isnt dead yet. I have configured the Code Example 1 on my website and it works fine, however, I want to format the search results as a table 3 columns wide. I dont really mind if all results are on one page, but I do need the table results. Can someone help me out?

Reply

Leave a Comment

CommentLuv Enabled

{ 2 trackbacks }

Previous post:

Next post:

ss_blog_claim=3cda7eab05e06ff8e7174874d923eb8e