I have a few sites that I use to make some pocket change off of. Some of these sites implement the tools provided by the eBay Partner Network which allows you to use widgets and the API to provide eBay listings on your own site. This can be a great way to bring in some extra money from your site if the site is product oriented.
I tend to use the eBay Custom Banner that you can find under the Tools->Widgets section after logging into the eBay Partner Network.
The Custom Banner allows you to create a widget in pretty much any size that you need that provides real time eBay listings. Along with choosing the size of the widget you can also select the colors to better match your site for a more seamless integration.
Creating The Custom Banner Widget
I’m not going to go into the details of creating the widget and changing dimensions and colors, it should be pretty self explanatory when you are looking at the page. Once you get done changing the size and the colors you will come across the Ad Content section for the widget.
In this section you choose which program you want to use for the widget, the campaign that you want to use for tracking purposes and the search term that will show items in the widget. The Custom ID and Category ID fields don’t apply to what we are doing so don’t worry about those. As you can see in the picture above I’ve filled out the fields that I mentioned. You can place any search term inside the field since we will be modifying this in a little bit.
Once you have those filled out you will receive the generated code in the section below.
This is the code you are going to use to add to your site to display the widget. If you look at it you can see the values that you set previously added into the 2nd <script> tag. Make sure you select the code and copy (Ctrl+C) to your clipboard.
Adding The Widget To Your Site
Now that we have the widget code ready we still need to implement the part where it fetches the title of the post and inserts it into the widget code automatically. For this we are going to use PHP. So we need to grab the title of the post, replace the spaces in the title with the + sign since that is what the eBay Custom Banner uses and then insert it into the widget code to get relevant listings for each post the widget is displayed on.
Find in area on your page where you want the widget to be displayed, I have mine displayed directly under the content. Make a new line in the file and add the following code.
<?php $title = the_title('', '', false);
$title = str_replace(' ', '+', $title);
echo "<script src='http://adn.ebay.com/files/js/min/ebay_activeContent
-min.js'></script>
<script src='http://adn.ebay.com/cb?programId=1&campId=5335962740
&toolId=10026&keyword=iPad&width=728&height=90&font=1&textColor=333366
&linkColor=333333&arrowColor=8BBC01&color1=B5B5B5&color2=FFFFFF'></script> ";
?>
Your widget code usually won’t be split up like this but I had to split it up in order to keep it from running across the page. I italicized the widget code, DO NOT use the code you see above but instead use the code that you had copied when creating the widget from earlier.
All that we have left to do is to replace the keyword in the widget code with our PHP variable to have it automatically provide listings based on the page title. Look inside the widget code and find &keyword=iPad. The keyword after the = will be whatever you set as the search term when you created the widget. If you used more than one word each word will be separated with a +.
Highlight the keyword after the = and replace it with “.$title.”. So your code should now look like the following.
<?php $title = the_title('', '', false);
$title = str_replace(' ', '+', $title);
echo "<script src='http://adn.ebay.com/files/js/min/ebay_activeContent
-min.js'></script>
<script src='http://adn.ebay.com/cb?programId=1&campId=5335962740
&toolId=10026&keyword=".$title."&width=728&height=90&font=1&textColor=333366
&linkColor=333333&arrowColor=8BBC01&color1=B5B5B5&color2=FFFFFF'></script>";
?>
Notice that after &keyword= that instead of the keyword we had previously we have now replaced it with our PHP variable. All that is left is for you to save the file and check out your page. Now, whenever you visit a page that the widget is displayed on it will show eBay listings relevant to the title of the post.


