Inspired by the rather enjoyable “meme(LaughingMeme – page 23, sentence 5: an autopsy)”:http://laughingmeme.org/archives/001960.html, I decided to integrate an ongoing series of Page 23 posts on my sidebar. To summarise the original aim of the meme, it has each participant write the fifth sentence on the 23rd page of the book they are currently reading. My slight subversion of the meme is to do the same for various books which I have read or am reading that I can recommend. The aim is to have a picture of the book, the sentence in question, and a link through to Amazon on my sidebar. I alsowant to vary the book displayed as often as possible. What I really want is a dynamic slideshow – which is what we are going to build now.

Accessing Amazon information with MTAmazon

First off download and install “MTAmazon”:http://mt-plugins.org/archives/entry/mtamazon.php, which uses Amazon’s “Web Services”:http://www.amazon.com/webservices to retrieve information on their catalogue (you’ll need to sign-up for a developer’s key). Using a book’s ASIN number (Amazon’s unique product ID) we can retrieve information about our books using the plugin. Displaying an image of the book and a link back to amazon is very easy:


">
" />

Which gives us this:

amazon.gif

Rather uninspiring, but styling it should be a simple matter.

Now we know how to get the information we want using an ASIN, but we want to store a series of these and cycle through them. My first thought was to create a new Page 23 category, and exclude it from normal page indexes using @MTCategories@. This does introduce a couple of problems however – firstly when we post to this category MT may go and ping various sites like bloglines or technorati informing them of a post which we want to hide from them. Secondly we have to littler our templates with exclusion clauses which is really ugly considering that we might only want to display our book in one place. Instead we’ll create a new blog for Page 23 posts.

A new Blog

The first thing we need to do is to remove all templates and archives for our slideshow blog. Now each entry is going to load the information we want from Amazon using the same code as we saw before – only this time each entry will have a different ASIN, with the Entry Body looking like this:


">
" />


As we are now using markup to format our entry, we don’t really want MT to try and convert page breaks, so set the default text formatting for this blog to none. Now at this point you might be saying “But hang on, you can’t put MT tags in an entry!” and you’d almost be right. Normally you can’t, however thanks to Brad Choate’s “postproc”:http://bradchoate.com/weblog/2002/07/06/mt-global-tag-attributes and Adam Kalsey’s “Process Tags”:http://mt-plugins.org/archives/entry/process_tags.php, we can. @Process Tags@ adds a global attribute to MT Entry tags, which when applies tells MT to look for and process and tags inside, like so:


Which tells MT to print out the body of an entry, and process any tags it finds inside. Such processing will increase our build times, but we’ll be using this in so few places it shouldn’t appreciably affect us.

Now you’ll be saying “But how are you going to get the entry into your main blog?”. Once again, someone made an MT plugin that makes me look clever. David Raynes’ “OtherBlog”:http://mt-plugins.org/archives/entry/otherblog.php allows me to load entries from other Blogs on the same Movable Type install. Putting that and Process Tags together and we get this code snippet which loads all entries from another blog, processes the tags inside them:






Which for our Page 23 blog will result in a nice list of book covers. So far so good. Next up, we need to grab a single book. We could easily grab the last added book using the @lastn=”1″@ attribute on @MTEntries@, however that isn’t going to give us a very dynamic sidebar. A better solution would be to display a random entry. Another plugin of David Raynes is “MTRandomEntries”:http://www.rayners.org/2002/12/26/mtrandomentries.php that can be used inside other container tags such as @MTOtherBlog@. Combining this we end up with our final solution:






Now if we put this code into site, each time we rebuild the page we’ll get a different random entry from the other blog. You can see this in action now on this site’s sidebar. Adding the fifth sentence is trivial – simply put the text into the Extended Entry field and use @$MTExtendedEntry$@ to return it. Using the MT rebuild script we could even schedule a cron job to periodically rebuild our site.

This solution can be used for a variety of tasks such an image slideshow or random quote generator. “Kottke”:http://www.kottke.org/ has taken the multiple-blog approach “a step further(Kottke.org undesign – The redesign continues…)”:http://www.kottke.org/03/11/kottke-redesign, and uses PHP to integrate five separate blogs into one seamless site – each blog’s entries are styled differently to differentiate them from one another (although Kottke uses PHP to achieve this).

Caveats

This solution isn’t perfect. Firstly it relies on quite a few MT plugins, which in turn have their own Perl module dependencies which your host may or may not provide. Secondly the bulk of your slideshow blog’s entries may end up being cut-and-paste markup with perhaps one or two different bits of text – I’m working on some better solutions to use templating, but so far all solutions have involved using PHP or Perl. Finally, we have to invoke a rebuild of the page to change the entry displayed – a better solution would be to return a different entry for each request (as seen on “Mezzoblue”:http://www.mezzoblue.com/), however again this would involve the use of PHP or Perl.