Amazon Machine Tags Plugin for WordPress

The forthcoming API change requiring signed requests will effect this plugin. If you do not update the plugin then it will stop working on August 15th. Comments on this version are closed, please comment on the update page.

In this article

Introduction

I always wanted to implement one thing since I started the blog: a simple inclusion of Amazon items. I didn’t want to search through results that existing plugins provided. When I wrote about something like a book, I already used machine tags to identify the subject! So I found the inspiration to write my first real WordPress plugin: Amazon Machine Tags.

Here’s what it does:

  1. It identifies any tag in the machine (or triple) tag form book:isbn=1234567890 or amazon:asin=1234567890. That works with native tags from WordPress 2.3 and later, Bunny’s Technorati Tags, Jerome’s Keywords, or as inline text (see below).
  2. Then it gets the item information and a thumbnail image from the Amazon Web Services API. That’s the real thing including prices and such, no cheap RSS feed. 😉
  3. The item(s) are displayed in the sidebar or in a blog article with a link to the visitor’s best match (if the ip2country plugin is installed) or a default Amazon shop of your choice. See examples in the sidebar.

    The “best match” is based on the visitor’s location. If she is from one of the six countries where Amazon has shops, that locale is chosen. If he is from Europe, the preferred language is matched to either France, Germany, or UK, with UK as default. If it’s neither a locale nor Europe, amazon.com is the default. Based on your location, do you think that’s a reasonable approach?

    Note that some items, like books in any language other than English, are only available from certain locales, so a visitor from the UK might not see German books you recommend.

  4. If you are an Amazon Associate for that locale, your Associate ID is included automatically.

You can edit the server-side, semantic and valid XHTML output via XSLT, change the CSS, or translate the admin interface through .po files. Actually Amazon loads the XSLT file from your server and processes it on theirs, so you shouldn’t block HTTP access to the plugin directory, and localhost doesn’t work either.

Results can be cached for anything between one second and one hour, so you don’t need to worry even when you run an extremely popular blog.

The YUI Connection Manager is included to verify the Access Key in the admin interface via REST and unobtrusive AJAX.

I hope this little piece of software serves you well and you like it.

Installation

  1. Get the latest version of the plugin from the WordPress site.
  2. Upload the whole amazon-machine-tags folder into the /wp-content/plugins/ directory.
  3. Activate the plugin through the “Plugins” menu in WordPress.
  4. Get an Amazon Web Services Access Key.
  5. Create a wp-content/cache/ directory with permissions set to 755, or 777 if you create the directory as root user.
  6. Put <?php AMTAP::get_items(); ?> in your sidebar and start using machine tags.
  7. Edit amtap-blog.css if you like.
  8. If you want to use tags in a blog article, write [amtap book:isbn=1234567890] or [amtap amazon:asin=1234567890]. Thanks to paulinepauline for that idea.

Frequently Asked Questions

Does it work in the sidebar on Pages, too?

Posts have tags, pages don’t, so it doesn’t work on those by default. But there’s a plugin called tags4page that enables tags for pages. Works like a charm.

Is there a limit of how many items can be requested?

Yes, Amazon has a limit of 10 items per request. Since they are separate requests, you can use a maximum of 10 items in the content plus a maximum of 10 in the sidebar.

Would it be possible to cache the images?

Technically it wouldn’t be a problem, but the Amazon Web Services license explicitly forbids caching of images (see 5.1.10). Sorry.

I need to a larger thumbnail (medium), but can’t seem to find a place to edit the size of the image being requested.

The image size can be edited in the XSLT. The original result is a XML file that is transformed by Amazon using your local copy of amtap-html-sidebar.xsl and amtap-html-content.xsl, respectively. Replacing every occurance of .//aws:TinyImage with .//aws:MediumImage should do the trick.

You can view the original XML when you activate the “debug” option in the admin interface so that the request string is printed as a comment in the sidebar’s source code. XSLT is a very powerful tool, and there’s a lot more in the XML, for example customer reviews.

Are all options really required?

No. The only required field is the Amazon Web Services Access Key. You can leave the others, they are set to defaults then.

Changelog

  • 3.0 (2009-07-31): Added signed requests for the new Amazon authorization requirement. Updated the API version to 2009-07-01 (please note: if you use your own XSL files, you must update the version in the XML namespace URL). Updated links.
  • 2.0 (2008-07-18):
    1. Added fields for editing the sidebar headline, link target, and displaying rating stars.
    2. Added an error message if the plugin is run from a private IP address space like localhost.
    3. Changed priorities for price selection, they are now: LowestNewPrice, ListPrice, first offer, LowestUsedPrice.
    4. Added support for the display of an artist name.
    5. Added rating stars.
    6. Fixed EAN numbers with a dash.
    7. Fixed cutting of titles after a period.
    8. Changed CSS and XSL files. Take care when you edited those.
  • 1.1.3: Changed amtap-admin.css and amtap-admin.inc.php to make the admin interface look prettier with WordPress 2.5.
  • 1.1.2: Fixed a bug in amtap.php when there are no other tags but default tags.
  • 1.1.1: Fixed the sort order of inline items, a bug for returning an error message when the cache file is not writable, and added Amazon’s limit of 10 items per request.
  • 1.1.0: Fixed the display of inline tags on the home page. Improved regular expression for filtering inline tags.
  • 1.0.6: Fixed a bug introduced through the new default items function when there were no items to be displayed in the sidebar.
  • 1.0.5: Added an option for default items on every page. Changed amtap-html-sidebar.xsl to sort items in the order of the request.
  • 1.0.4: Bugfix for replacement of dollar characters in content. Also content items are now cached separately.
  • 1.0.3: Fixed the display of inline tags on category pages.
  • 1.0.2: Changed the plugin path from amtap to amazon-machine-tags for consistency with the file structure in the zipped file.
  • 1.0.1: Bugfix for native WordPress tags.

202 Responses to ‘Amazon Machine Tags Plugin for WordPress’

  1. Dieter

    Hallo Martin,

    ich wollte einfach mal Danke für Dein tolles WP-Plugin sagen. Es läuft auf meinen beiden WordPress-Installationen einwandfrei.

    Ich hoffe, es klappt alles mit dem API change requiring authentication update.

    Beste Grüße
    Dieter

  2. Robertino

    >In the meantime: if you don’t know XSLT or CSS, don’t touch it.
    I do know XSLT, XML, CSS, etc., but only from ILE RPG. (PHP is coming up fast though..)
    Yes, I’m an oldy. I started programming on System/38, then, AS/400, iSeries, System i, i5.

    I’ll just play around with it at one of my throwaway blogs.
    Nothing an overwriting FTP session can’t resolve there.

    Thanks for the wonderful plugin.
    Robert