Add Ebay auctions to your website in 5 minutes
Update: I mentioned that I would cover including your Ebay affiliate link in the feed in a later article, however, had I paid closer attention I would have seen that the affiliate link can easily be included when you create the feed.
Under advanced search go down to “Affiliate Tracking Information” and click show. Choose Commision Junction as the provider and enter your PID. That’s it know the feed links will include your affiliate id and you can get commissions on traffic you refer.
Have you ever wanted to add Ebay auctions to your website? Well, I’ll show you in a few easy steps how to do just that.
Getting started
Before we get into the real meat of this post we need to put some things in place. You will need the class file, which is below, and the url to the RSS feed you want to use. With these two things in place you will be able to add your feed in just four lines of code.
The RSS feed
Whenever you do a search on Ebay you are provided with an rss feed for that search. You will see the small orange RSS image after the search results in the Tools section. Here is an example of a seach RSS feed.
The class file
Save this file as EbayRssFeed.class.php and place it in the same directory as the php file you want to include the feed on.
<?php
class EbayRssFeed {
private $url;
private $feed;
public function __construct($url) {
$this->url = $url;
$this->feed = simplexml_load_file($url);
}
private function getItems() {
return $this->feed->channel->item;
}
public function writeFeed() {
$items = $this->getItems();
echo "\n\n<!--EBAY RSS FEED-->\n";
for($i=0;$i<count($items);$i++) {
echo "<div class=\"EbayRssFeed\">\n\t<div class=\"EbayRssTitle\">" .
"<a href=\"" . $items[$i]->link . "\">" . $items[$i]->title . "</a></div>" .
"\n\t<div class=\"EbayRssDescription\">" . $items[$i]->description . "</div>\n</div>\n\n";
}
echo "<!--/EBAY RSS FEED-->\n\n";
}
}
?>
Adding the feed
Now that we have that out of the way let’s add that RSS feed.
First we will create the class instance.
//include the class file
require_once("EbayRssFeed.class.php");
//the url to our RSS feed
$file = 'http://rss.api.ebay.com/ws/rssapi?FeedName=SearchResults&siteId=0&language=en-US&output=RSS20&catref=C5&sacqy=&sacur=0&sorefinesearch=1&from=R14&fbd=1&saobfmts=exsif&_trksid=m37&dfsp=2&sacqyop=ge&saslc=0&floc=1&sabfmts=0&saprclo=250&saprchi=&saaff=afdefault&sabdlo=2&ftrv=1&sabdhi=&ftrt=1&fcl=3&frpp=50&afcj=&nojspr=y&satitle=vacation&afmp=&sacat=29578&saslop=1&fss=0';
//create the instance
$ebay = new EbayRssFeed($file);
Now, that wasn’t too hard was it?
Place the following code in your php page where you would like the feed to show.
<?= $ebay->writeFeed() ?>
Finishing up
Your done! That really is all there is to it. I plan on covering this in a later post and integrating your Ebay affiliate id so you can earn some cash from the users that are referred by your feed.
You can check out a demo that I made. Enjoy!
RSS ?
5 comments on this post
you didn’t say where to put the class instance. you say *first we will create the class instance* but do not say where you create it. is this in the stylesheet?
$ebay = new EbayRssFeed($file); is setting up the class instance so $ebay is now an instance of the EbayRssFeed class.
Classes in object oriented programming are quite different from classes in CSS.
I’m confused. I created the class instance but what do I do with it? Do I add it to the class file?
Thanks for your help.
You just put $ebay->writeFeed() in your page where ever you want the auctions to show up.
Hi Dennis,
I believe you simply add the ‘class’ information into the flow of your document, probably after the head section.