mitcho Michael 芳貴 Erlewine

Postdoctoral fellow, McGill Linguistics.


Archive for the ‘metablog’ Category

This is what a release looks like

Wednesday, December 10th, 2008

This is what the latest release (2.1.6) of my Yet Another Related Posts Plugin looked like under Mint, using my WordPress plugin downloads pepper, which in turn gets its data from

It’s always interesting to see these release spikes in download traffic. Note that this release was on the Wednesday but that was during the day, so Wednesday’s traffic is still higher than the normal ~300/day level, while the big peak (by day) is on Thursday. Too bad doesn’t give me hourly stats, though I guess that would be a little ridiculous.

YARPP is just about at that 35k download mark. I’m looking forward to the next release. ^^

Display your rankings using PHP 4’s XSLT support

Friday, February 1st, 2008

With all the exciting recent news about, I thought I would document a simple bit of code I added to my site the other day. offers a number of [[Flash]]-based widgets you can add to your website. Unfortunately, this doesn’t give you much flexibility and, of course, requires Flash. But you, dear friend, have a site written in [[PHP]], and the rankings are just XML files. There is a better way.

Looking around on the web, there are some good instructions and recommendations for using PHP 5’s object-oriented XML support. But, as we know, not everyone is using PHP 5. Here’s what I did on my PHP install, which includes the DOM/XML and DOM/XSLT extensions.1

Write your XSL Transformation

The first step is to write your [[XSL Transformation]], or XSLT, a special XML “program” which takes an XML file and reformats it into another XML file. Remember when you learned in Algebra class what a function was? An XSLT defines a function from XML to XML. In our case, we need to take a special proprietary XML file like the this one for my weekly top artists and return some solid XHTML.

Let’s take a look at the XSLT I used: (it helps to take a look at the original XML file at the same time.)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="">
<xsl:template match="weeklyartistchart">
<xsl:apply-templates select="artist[position() &lt; 6]"/>
<xsl:template match="artist">
<li><a><xsl:attribute name="href"><xsl:value-of select="./url"/></xsl:attribute><xsl:value-of select="./name"/></a><span><xsl:value-of select="./artist"/></span>: <xsl:value-of select="./playcount"/></li>

The full spec description will give you all the juicy details, but you really only need a few basic details (or you can just steal my code). First, we note the <xsl:template match="weeklyartistchart"> and <xsl:template match="artist"> items. Each of these code blocks describe what to do to each <weeklyartistchart> and <artist> nodes, respectively, in the input XML. In the code above, when a <weeklyartistchart> is found, an ordered list is opened and the artist template is applied to the first five (position() &lt; 6) <artist> nodes. In the artist template (<xsl:template match="artist">), the script takes each <artist> and prints a list item with the name of the artist, with a link to the url given in the original <artist>’s <url> subnode.

Process the XML with your XSLT

Once your XSLT is written, save it to a file, like Now we’ll use the DOM/XSLT extension and apply this XSLT file to the live weekly artist chart XML file from Here’s the code I used:

$chartxml = domxml_open_file("/weeklyartistchart.xml");
$xslt = domxml_xslt_stylesheet_file("");
$charthtml = $xslt->process($chartxml);
echo $charthtml->dump_mem();

The code is pretty self explanatory—just four lines: 1. open the remote XML file using domxml_open_file, 2. open the stylesheet (XSL transformation), 3. apply the stylesheet to the remote XML file, and 4. echo the output.

That’s it! You can see the results here on my music page.

  1. To see if these instructions will work for you, check your phpinfo for the lines “DOM/XML enabled” and “DOM/XSLT enabled”. If the items aren’t even showing up, you’re out of luck. :( There are, however, other comparable methods to process XML and XSLT in PHP 4.
    dom/xml check 

Bailey’s in the Tribune!

Friday, January 18th, 2008

Kuviasungnerk/Kangeiko just put Bailey on the front page of! ^^ You kind of have to see a different page to know who it is, though.1 Heh.

I recently got Daring Fireball‘ed too,2 so that almost makes us a celebrity couple.

Bailey on the Tribune

I personally like the caption right above. That’s the same story, right?

  1. “Good thing I have nice eyebrows, ‘cause that’s all you can see.” 

  2. This article: Great News! You can opt-out from Omniture’s mitcho on DF 

Yet Another Related Posts Plugin

Saturday, December 29th, 2007


This posting is now outdated… for the latest information on YARPP, please visit YARPP’s very own page on my site, or its page on If you have questions, please submit on the forum. Thanks!


Today I’m releasing Yet Another Related Posts Plugin (YARPP1) 1.0 for WordPress. It’s the result of some tinkering with Peter Bowyer’s version of Alexander Malov & Mike Lu’s Related Entries plugin. Modifications made include:

  1. Limiting by a threshold: Peter Bowyer did the great work of making the algorithm use [[mysql]]’s fulltext search score to identify related posts. But it currently just displayed, for example, the top 5 most “relevant” entries, even if some of them weren’t at all similar. Now you can set a threshold limit2 for relevance, and you get more related posts if there are more related posts and less if there are less. Ha!
  2. Being a better plugin citizen: now it doesn’t require the user to click some sketchy button to alter the database and enable a fulltext key. Using register_activation_hook, it does it automagically on plugin activation. Just install and go!
  3. Miscellany: a nicer options screen, displaying the fulltext match score on output for admins, an option to allow related posts from the future, a couple bug fixes, etc.


Just put it in your /wp-content/plugins/ directory, activate, and then drop the related_posts function in your WP loop. Change any options in the Related Posts (YARPP) Options pane in Admin > Plugins.

You can override any options in an individual instance of related_posts using the following syntax:

`related_posts(limit, threshold, before title, after title, show excerpt, len, before excerpt, after excerpt, show pass posts, past only, show score);

Most of these should be self-explanatory. They’re also in the same order as the options on the YARPP Options pane.

Example: related_posts(10, null, 'title: ') changes the maximum related posts number to 10, keeps the default threshold from the Options pane, and adds title: to the beginning of every title.

There’s also a related_posts_exist) function. It has three optional arguments to override the defaults: a threshold, the past only boolean, and the show password-protected posts boolean.


For a barebones setup, just drop <?php related_posts(); ?> right after <?php the_content() ?>.

On my own blog I use the following code with <li> and </li> as the before/after entry options:

<?php if (related_posts_exist()): ?>
<p>Related posts:
<?php related_posts(); ?>
<?php else: ?>
<p>No related posts.</p>
<?php endif; ?>

Coming soon (probably)

  1. Incorporation of tags and categories in the algorithm. I’ve gotten the code working, but I still need to think about what the most natural algorithm would be for weighing these factors against the mysql fulltext score currently used (and works pretty well, I must say).
  2. Um, something else! Let me know if you have any suggestions for improvement. ^^

Version log

1.0 Initial upload (20071229)

1.0.1 Bugfix: 1.0 assumed you had Markdown installed (20070105)

  1. Pronounced “yarp!”, kind of like this, but maybe with a little more joy:

  2. Did you know that threshold has only two h’s!? I’m incensed and just went through and replaced all the instances of threshhold in my code. It’s really not a thresh-hold!? 

Introducing Smartdate

Tuesday, November 27th, 2007

I recently have been working on a WordPress plugin called WP-Smartdate and I’m happy to say that it is hosted at starting today. As some people have noticed, my blog recently has included little links on word like “yesterday,” with a machine readable version of the date reference (called a “microformat” in the biz). Download the plugin and get started!

WP-Smartdate 0.1
4 kb - zip

This blog post describes release 0.1… For the latest description, check out the WP-Smartdate plugin page or

Please comment! I would love to hear your feedback on the plugin.


WP-Smartdate looks for relative date expressions in your blog posts, such as “tomorrow,” “this coming Monday,” “last Friday,” and adds the date reference (like “2007-11-26”) as a machine-readable microformat.

Why Smartdate?

WP-Smartdate was created for three simple audiences:

  1. For the machine: While many professional information retrieval algorithms go far beyond the scope of this program, smartdate helps the process along by adding machine-readable tags to relative date expressions.1 In addition, these machine tags, in turn, help the human: a search on Google for “November 7th, 2007,” for example, will not pull up a document talking about “yesterday,” written on the 8th, but it will pull up the smartdate output of 2007-11-07.
  2. For the human reader: Blog posts are often written in the “now,” using relative time expressions without concern for how the text will be read in the future. WP-Smartdate makes such posts easier to read and comprehend temporally2.
  3. For me: Because I think this sort of thing is fun!

A typology of smartdate date expressions

The following types of expressions are resolved with respect to the speech time—in WP-Smartdate’s case, the blog post date.

  1. simple references: “yesterday,” “today,” “tomorrow,”
  2. next/last DOTW expressions: “next Friday,” “this past Sunday,” “this Monday”

For the future

  • static dates: “January 1st, 2007”
  • duration shift expressions: “5 days ago,” “fourscore and seven years ago”
  • day of the week shifts: “2 Fridays ago”
  • clean up the code!

  1. One could argue that relative dates are a perfect place to use the abbr tag, as they are a sort of natural-language shortcut for more static temporal expressions. In fact, WP-Smartdate’s output also follows the datetime microformat design pattern draft with two caveats: 1. Unfortunately, the datetime semantic class has not yet been set as the standard is a draft. WP-Smartdate uses datetime. See the Date and Time datatype proposal for more information. 2. The current recommendation for datetime pushes for following the W3C datetime profile, which does not support the ISO-8601 time interval specification, which is will be used by WP-Smartdate. 

  2. Even though the abbr tag should only be used for machine reading

Yes, I have a blog

Friday, August 31st, 2007

Welcome to mitcho’s 部落格 (bùlùogé)! While some people may be surprised to hear that I am just starting to blog, this post is my first ever blog post. I hope to update any and all readers on life in Taiwan: teaching, learning, and doing.

The goal is to document my experience and thoughts. I fully expect my biggest reader to be myself. ^^

“By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest.” -Confucius (citation needed)


ps: I’m experimenting with WordPress and my custom theme… please be patient as I tweak this setup to match my needs. :)

pps: Oh no! My Chinese is MIA! Wehave to fix that, won’t we? UPDATE: Fixed.