Way too many games

Ok, my games index is now live. It's a fairly complete list, although I know there are a bunch of DOS games that aren't on there just because I don't have them with me anymore (they're at home with Mom and Dad collecting dust). Anyway have a peek. If you're geographically nearby let me know if you'd like to borrow something. (While I'm at it, I might as well make this a Movable Type tip-- click the 'more' link for the goods.)

For you Movable Type fans, here's how this page is done.

I set up a completely separate blog for my 'stuff'. Games are the first things I put in it, but others will be added (DVDs, CDs, books, etc.).

I only have 1 index page in the blog currently, and that's the one that produces 'games.php'. This index page contains a mix of PHP and MT code. The PHP code is used to count the number of games (total and by system) and to keep track of which ones are completed (the ones completed are in bold).

Each game system is set up as a separate category. There are general categories in the blog like 'Games', 'DVD', etc. Then the system specific categories such as 'Games: GC' for all GameCube games. This allows me to select those entries separately for display on the index (the MTEntries tag shown below should be all on one line instead of wrapped as I've formatted it here):

<img src="/images/games_gc_head.jpg" 
 height="108" width="250" alt="GameCube"
 border="0" /><br />

<MTEntries sort_by="title" sort_order="ascend"
 lastn="9999" category="Games: GC">
    <a href="/stuff/gameview.php?<$MTEntryID$>">
  <?= $completed[<$MTEntryID$>]
    ? '<b>' : '' ?>
  <?= $completed[<$MTEntryID$>]
    ? '</b>' : '' ?>
  </MTEntryIfExtended><br />
  <?php  $system['GC']++; ?>
<b>Total: <?= $system['GC']+0 ?></b><br />

Above, the PHP code is counting the number of 'GC' games in the 'system' variable (variable that holds counts by system). The '$completed' array was populated earlier in the script with another MTEntries loop.

Another bit of magic is in the Individual Archive Template. I use my 'Key/Values' plugin to store metadata about the games in the entry's 'additional entry text' field. Things like my personal rating for the game, the Amazon 'ASIN' code, the game developer, etc. I pull these out and populate them into a PHP variable like this:

<MTKeyValues iterate="1">
  $values['<$MTKeyName encode_php="q"$>'] =
      '<$MTKeyValue encode_php="q"$>';

I also use Adam Kalsey's Amazon plugin for retrieving some information from Amazon.com-- such as the game image and the ESRB rating (the game equivalent of the MPAA rating assigned to movies) (the MTAmazon tag below should all be on one line instead of how I've formatted it here):

<MTAmazon devtoken="my-developer-token"
 associateid="bradchoate" method="Asin"
 search="[MTKeyValue key='amazon_asin']">
  $amazon['url'] = '<$MTAmazonLink encode_php="q"$>';
  $amazon['image'] = '<$MTAmazonMediumImage
  $amazon['esrb'] = '<$MTAmazonField
      name="EsrbRating" encode_php="q"$>';

I use the KeyValues plugin above since I'm pulling the 'amazon_asin' key from the entry and using it for the Amazon web services lookup.

The rest of it is just outputting the various values. Like the personal rating I assign for some games:

<?php if ($values['rating']) { ?>
<b>Personal Rating (1-5 stars)</b><br />
<?= rating($values['rating']) ?><br /><br />
<?php } ?>

Now, here's the last piece of the puzzle. The Amazon web services agreement actually requires that you refresh any content you pull from their site at least every 24 hours. (If you're display prices, they expect those to be cached no more than 1 hour!) Now with MT, you aren't normally able to dynamically render entries. But in my case, I have to or I won't be abiding by my agreement. Well, I decided to do a couple of things.

First of all, the pages couldn't be static. So I created a CGI called 'mt-view.cgi' which allows you to dynamically build a Movable Type individual entry template for a given entry.

Then I needed a way to run the PHP code I use in my templates since my layout uses it. So I created a little PHP wrapper that does this:

  if (cache_block('game:'.$_SERVER['QUERY_STRING'],
      time_span(1))) {

That script invokes the CGI and outputs the result, but because it's done as an include, it parses the PHP code that is returned! Now the 'cache_block' function you see there causes the content to be cached within my file system for up to 1 day. That satisfies the Amazon web services requirement.

Whew! That's it. If you're interested in the 'cache.php' script, you can download it here: phpcache.zip

If you'd like to try out mt-view.cgi, you can download that here: mtview-1_0.zip

Questions or comments? Feel free to post them right here.

Update: I've decided to simply rebuild my entries daily. I'm automating this using a script called mt-rebuild.pl (download here). This means I can use plain links to the static pages produced from MT. It also means that users don't have to suffer through waiting for a dynamic Amazon web services request to run if they view a page that requires a refresh.


TrackBack URL for this entry:

Listed below are links to weblogs that reference Way too many games:

» Unconventional use of MTAmazon from Kalsey Consulting Group
Brad Choate is using the MTAmazon plugin on his video games pages, not to link to products for purchase, but mainly to display pictures of the games and the ESRB rating. Read about how he creates the pages in Way Too Many Games. [Read More]

» New MTAmazon feature from Paul's Down-Home Page
I've been meaning to supplement the book review engine on this site with better links to Amazon, using Adam Kalsey's [Read More]

» Being legal in a cool way from A young man's Site Log
Rebuild MT blogs the easy way on a schedule. [Read More]

» New Movies Section from Weblog
Well, I must admit, Brad Choate is one smart dude. I stumbled across this post of his, which describes how he set up his Games index, and I knew I had to have something like that on my site. I... [Read More]

» Amazon in blog from I Kill Spies
Amazon web services: There are 2 options, one where you just host images yourself, and the webservices version, where the entire content comes from amazon.com Problem: the iframe served is BIG and the URL is thus far difficult to parse Give it up, you ... [Read More]

» Bits and Pieces from Blog de Halavais
Added two things to the UBlog: A listing of recent posts and an alphabetized list of blogs on the site.... [Read More]

» Dynamically-generated MT category archives from Fuddland
I've never really figured out the best thing to do with entry categories. There are some categories for which I want to gather all the relevant entries into one archives--for example, photo-based or music-related entries--but MT has this "all-or-nothin... [Read More]


amancay said:

hmmm... almost what I'm looking for, I want to list my cds out... but I want the archives (prev and next links) to list them in alphabetical order as opposed to when I entered the info...
can you help?

tamaracks said:

I really like the idea of a cron job that can rebuild pages, but is there a way to make it rebuild index templates instead of entries? I want to rebuild the page that holds my wishlist items.

funvill said:

I’m trying to use ‘Key/Values’ plug-in for the amazon_asin value. In the
MTAmazon plug-in like you have done above. But every time I rebuild the page I
get this error "<MTAmazon> with no </MTAmazon>"

I can build the page normally if I manually put in the amazon_asin value and I
can display values with ‘Key/Values’ no problem. But when I try too combined the
two I get that error.
All my file are .php

Here is what I have tried
<MTKeyValues><MTAmazon method="Asin" search="<MTKeyValue key="amazon_asin">"></MTKeyValues>
<MTKeyValues><MTAmazon method="Asin" search="[MTKeyValue key='amazon_asin']"></MTKeyValues>

<MTKeyValues><MTAmazon method="Asin" search="[MTKeyValue key='amazon_asin']"></MTKeyValues>

this is in my Extended Entry section for all my entrees

Any help/suggestion would be great appreciated

Movable Type v2.6
mtkeyvalues v1.53
MTAmazon v2.2


This article was published on August 2, 2002 10:37 PM.

The article previously posted was MTAuthors.

The next article is XHTML 2 Working Draft.

Many more can be found on the home page or by looking through the archives.

Powered by Movable Type