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">
<MTEntryIfExtended>
<a href="/stuff/gameview.php?<$MTEntryID$>">
</MTEntryIfExtended>
<?= $completed[<$MTEntryID$>]
? '<b>' : '' ?>
<$MTEntryTitle$>
<?= $completed[<$MTEntryID$>]
? '</b>' : '' ?>
<MTEntryIfExtended>
</a>
</MTEntryIfExtended><br />
<?php $system['GC']++; ?>
<MTEntriesFooter>
<b>Total: <?= $system['GC']+0 ?></b><br />
</MTEntriesFooter>
</MTEntries>
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:
<?php
<MTKeyValues iterate="1">
$values['<$MTKeyName encode_php="q"$>'] =
'<$MTKeyValue encode_php="q"$>';
</MTKeyValues>
?>
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):
<?php
<MTKeyValues>
<MTAmazon devtoken="my-developer-token"
associateid="bradchoate" method="Asin"
search="[MTKeyValue key='amazon_asin']">
$amazon['url'] = '<$MTAmazonLink encode_php="q"$>';
$amazon['image'] = '<$MTAmazonMediumImage
encode_php="q"$>';
$amazon['esrb'] = '<$MTAmazonField
name="EsrbRating" encode_php="q"$>';
</MTAmazon>
</MTKeyValues>
?>
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:
<?php
require('cache.php');
if (cache_block('game:'.$_SERVER['QUERY_STRING'],
time_span(1))) {
include('http://www.bradchoate.com'.
'/mt/mt-view.cgi/11,'.
$_SERVER['QUERY_STRING'].',115');
}
?>
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.
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?
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.
hello
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
1)
<MTKeyValues><MTAmazon method="Asin" search="<MTKeyValue key="amazon_asin">"></MTKeyValues>
2)
<MTKeyValues><MTAmazon method="Asin" search="[MTKeyValue key='amazon_asin']"></MTKeyValues>
<?php
<MTKeyValues><MTAmazon method="Asin" search="[MTKeyValue key='amazon_asin']"></MTKeyValues>
?>
this is in my Extended Entry section for all my entrees
key=value.
rating=3
amazon_asin=B00005RL3Y
Any help/suggestion would be great appreciated
funvill
Movable Type v2.6
mtkeyvalues v1.53
MTAmazon v2.2