Amazon.com associates, use this code to easy display best sellers based on whatever search terms you want The results are cached and refreshed every 12 hours, speeding the performance of your website. Once you've finished the main setup, adding custom best seller lists all over your website will be a snap!
First, copy the XSL template from below and save it on your web server with the filename "Amazon2RSS-2.0.xsl".
Second, copy the following code and save it in a file named "Amazon2RSS-2.0.php". Make the following changes, and then upload the file to the same directory as carp.php:
<?php
$xslt='http://www.yourdomain.com/xsl/Amazon2RSS-2.0.xsl';
$AccessKeyId='put_your_access_key_id_here';
$AssociateTag='put_your_associates_id_here';
$country='US';
$countries=array(
'CA'=>'ecs.amazonaws.ca',
'DE'=>'ecs.amazonaws.de',
'FR'=>'ecs.amazonaws.fr',
'JP'=>'ecs.amazonaws.jp',
'UK'=>'ecs.amazonaws.co.uk',
'US'=>'ecs.amazonaws.com'
);
if (!($MaxItems+=0)) $MaxItems=5;
if (!($OneReview+=0)) $OneReview=1;
$MaxReviewLength+=0;
if (!isset($SearchIndex)) $SearchIndex='Books';
require_once dirname(__FILE__).'/carp.php';
CarpConf('cborder','');
CarpConf('iorder','image,link,author,desc');
CarpConf('cacheinterval',720);
CarpConf('maxitems',$MaxItems);
CarpConf('linktarget',1);
CarpConf('aidesc','');
CarpConf('ai','<br clear="all" /> <br />');
CarpConf('biimage','<div style="float:left;margin-right:5px;">');
CarpConf('aiimage','</div>');
$query='http://'.$countries[$country].'/onca/xml?Service=AWSECommerceService'.
'&Operation=ItemSearch&ResponseGroup=Small,Reviews,Images,Offers'.
"&AWSAccessKeyId=$AccessKeyId&AssociateTag=$AssociateTag".
"&Sort=salesrank&Style=".urlencode($xslt)."&Keywords=".urlencode($q).
"&SearchIndex=".urlencode($SearchIndex).
($OneReview?'&CaRPOneReview=1':'').
($MaxReviewLength?"&CaRPMaxReviewLength=$MaxReviewLength":'');
if (0) echo "<p>$query</p>";
CarpCacheShow($query);
?>Third, find an Amazon.com logo you like and upload a copy of it to your website.
Finally, copy the following code (which will be a template for adding Amazon links to your web pages) and save it on your computer, changing:
<div style="width:200;height:420px;overflow:auto;margin:5px;padding:5px;background:#cccccc;"> <span style="color:#003366;font-size:16pt;font-weight:bold;">Best sellers from</span><br> <a href="http://www.amazon.com/exec/obidos/redirect?tag=moulc&path=subst/home/home.html"><img src="http://www.yourwebsite.com/img/126X32-w-logo.gif" border="0"></a><br> <?php $q='web design'; $MaxItems=5; $OneReview=1; $MaxReviewLength=250; $SearchIndex='Books'; include '/path/to/Amazon2RSS-2.0.php'; ?> </div>
You've completed the main setup. Now you can add Amazon links to any page by pasting a copy of the code saved in the last step above into your web page with the following changes as needed:
That's it! Depending on whether you are using the free or commercial version of CaRP, something like the examples to the right will appear on your web page.
TROUBLESHOOTING: If you follow the above steps and no items are displayed:
If what is displayed is in RSS format, then the XSL part of the system is working, and you need to figure out why CaRP isn't displaying it. More likely, it won't be in RSS format, but will be in Amazon's XML format. Hopefully there will be an error message in it somewhere telling you what went wrong. If not, things to check include:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Raymond Yee (yee@uclink.berkeley.edu) , Interactive University, University of California, Berkeley 2002-07-26
Adapted for RSS 2.0, ECS 4.0, made configurable, etc. by Antone Roundy 2005-10-26
Raymond Yee yee@uclink.berkeley.edu Interactive University Project Amazon Lite to RSS 0.92 XSLT
Copyright (c) 2002 The Regents of the University of California
Permission is hereby granted, without written agreement and without
license or royalty fees, to use, copy, modify, and distribute this XSLT
style sheet for any purpose, provided that the above copyright notice
and the following two paragraphs appear in all copies of this
document.
IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF THIS DOCUMENT TYPE DEFINITION, EVEN IF THE
UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE COMPUTER
FILE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
trick from http://www.mycgiserver.com/~~lisali/papers/paper.htm
-->
<!DOCTYPE stylesheet [
<!ENTITY nbsp "<xsl:text disable-output-escaping="yes"
xmlns:xsl= "http://www.w3.org/1999/XSL/Transform "
>&nbsp;</xsl:text>">
]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2005-10-05"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<xsl:output encoding="UTF-8" method="xml" media-type="text/xml"/>
<xsl:template match="aws:ItemSearchResponse">
<xsl:variable name="CaRPOneReview">
<xsl:choose>
<xsl:when test="aws:OperationRequest/aws:Arguments/aws:Argument[@Name = 'CaRPOneReview']/@Value">
<xsl:value-of select="aws:OperationRequest/aws:Arguments/aws:Argument[@Name = 'CaRPOneReview']/@Value" />
</xsl:when>
<xsl:otherwise><xsl:text>0</xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="CaRPMaxReviewLength">
<xsl:choose>
<xsl:when test="aws:OperationRequest/aws:Arguments/aws:Argument[@Name = 'CaRPMaxReviewLength']/@Value">
<xsl:value-of select="aws:OperationRequest/aws:Arguments/aws:Argument[@Name = 'CaRPMaxReviewLength']/@Value" />
</xsl:when>
<xsl:otherwise><xsl:text>250</xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<rss version="2.0">
<channel>
<title>Amazon Search Results</title>
<link>http://www.amazon.com/</link>
<description>Amazon Search Results</description>
<xsl:apply-templates select="aws:Items/aws:Item">
<xsl:with-param name="CaRPOneReview" select="$CaRPOneReview" />
<xsl:with-param name="CaRPMaxReviewLength" select="$CaRPMaxReviewLength" />
</xsl:apply-templates>
</channel>
</rss>
</xsl:template>
<xsl:template match="aws:Items/aws:Item">
<xsl:param name="CaRPOneReview" select="''"/>
<xsl:param name="CaRPMaxReviewLength" select="''"/>
<item>
<title><xsl:value-of select="aws:ItemAttributes/aws:Title"/></title>
<link><xsl:call-template name="fixurl">
<xsl:with-param name="string" select="aws:DetailPageURL"/></xsl:call-template></link>
<dc:creator><xsl:for-each select="aws:ItemAttributes/aws:Author">
<xsl:apply-templates/>
<xsl:if test="not(position()=last())">, </xsl:if>
</xsl:for-each></dc:creator>
<description>
<xsl:choose>
<xsl:when test="$CaRPOneReview = '1'">
<b>Amazon Price:</b> <xsl:value-of select="aws:Offers/aws:Offer[1]/aws:OfferListing[1]/aws:Price/aws:FormattedPrice"/>
<xsl:apply-templates select="aws:CustomerReviews/aws:Review[1]">
<xsl:with-param name="CaRPOneReview" select="$CaRPOneReview" />
<xsl:with-param name="CaRPMaxReviewLength" select="$CaRPMaxReviewLength" />
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<b>Amazon Price:</b> <xsl:value-of select="aws:Offers/aws:Offer[1]/aws:OfferListing[1]/aws:Price/aws:FormattedPrice"/><br />
<b>Customer Reviews:</b>
<xsl:apply-templates select="aws:CustomerReviews/aws:Review">
<xsl:with-param name="CaRPOneReview" select="$CaRPOneReview" />
<xsl:with-param name="CaRPMaxReviewLength" select="$CaRPMaxReviewLength" />
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</description>
<!-- length="1000" is not accurate, but what can we do? we don't know the size of the file -->
<xsl:choose>
<xsl:when test="contains(aws:SmallImage/aws:URL,'.gif')"><enclosure url="{aws:SmallImage/aws:URL}" length="1000" type="image/gif" /></xsl:when>
<xsl:when test="contains(aws:SmallImage/aws:URL,'.jpeg') or contains(aws:SmallImage/aws:URL,'.jpg')"><enclosure url="{aws:SmallImage/aws:URL}" length="1000" type="image/jpeg" /></xsl:when>
<xsl:when test="contains(aws:SmallImage/aws:URL,'.png')"><enclosure url="{aws:SmallImage/aws:URL}" length="1000" type="image/png" /></xsl:when>
</xsl:choose>
</item>
</xsl:template>
<xsl:template match="aws:CustomerReviews/aws:Review">
<xsl:param name="CaRPOneReview" select="''"/>
<xsl:param name="CaRPMaxReviewLength" select="''"/>
<xsl:choose>
<xsl:when test="$CaRPOneReview = '1'">
<br/>
<b>Customer Review:</b> <xsl:value-of select="substring(aws:Content,1,$CaRPMaxReviewLength)"/><xsl:if test="string-length(aws:Content)>$CaRPMaxReviewLength">...</xsl:if>
</xsl:when>
<xsl:otherwise>
<br/>&raquo; <xsl:value-of select="substring(aws:Content,1,$CaRPMaxReviewLength)"/><xsl:if test="string-length(aws:Content)>$CaRPMaxReviewLength">...</xsl:if>
<xsl:if test="not(position()=last())"><br /></xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="fixurl">
<xsl:param name="string" select="''"/>
<xsl:choose>
<xsl:when test="contains($string,'%26')">
<xsl:value-of select="substring-before($string,'%26')"/>&<xsl:call-template name="fixurl">
<xsl:with-param name="string" select="substring-after($string,'%26')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>CaRP commercial version:






CaRP free version:
