I have created a ratings system that works along with the movie reviews that I write. Using Movable Type, some plugins, and a little bit of PHP, the ratings appear next to each review in the individual archive. Here I will explain how I implemented this system, knowing full-well that there are many different ways to accomplish this task. Some of the choices I made were made out of necessity (could not get a particular plugin working). And there might be a more efficient way to code the PHP, but this is the first PHP script that I wrote by myself. On with the directions . . .

First, you need some plugins: Filter Categories and the Tags plugin. The Filter Categories plugin is used to filter out all categories except the “movie reviews” category; if the entry category is not Movie Reviews, the code is not processed.

The Tags plugin is used to store the rating. I could have used other keyword plugins for Movable Type, but I couldn’t get them to work, therefore I used Tags. I also used Tags because I might use the plugin in the future for other features. Inside the tags field ratings are expressed as “6=movie_rating”, for example; I specify “movie_rating” because I am not sure how I might use Tags in the future. When I need the rating, I use the Movable Type global attribute “trim_to=’1′” within MTTagName.

In my rating system there are three possible text strings that describe the film, and that text corresponds to the numerical rating. A rating between 1 and 3 = “horrible!”; between 4 and 6 =”good.”; and between 7 and 9 =”damn good!”. I use the PHP to process the text strings to print.

Now, the code:


<MTFilteredEntryCategories include="Movie Reviews">
<MTEntryTags>
<?php

$horrible="horrible!";
$good="good.";
$damngood="damn good!";
$rating=<MTTagName trim_to="1">;

if ($rating <=3) {
$ratingname=$horrible;
}
elseif (($rating >=4) && ($rating <=6)) {
$ratingname=$good;
}
else {$ratingname=$damngood;}

print "<p class="sidetext">This movie is rated <strong>$rating/9</strong>. It's a "$ratingname" movie.</p>\n

<p class="sidetext">What's a "$ratingname" movie? Read about
<a title="read about the method to my madness" href="<$MTLink entry_id="513"$>">my rating method here</a>.</p>\n";

?>
</MTEntryTags>
</MTFilteredEntryCategories>

That’s it. Considering it’s my first script, I would consider this straight forward. But, here is some brief explanation. First, I open a Filtered Categories tag that corresponds to the current entry, then I open the Tags tag. Beginning with the PHP I declare the variables. I know this wasn’t totally necessary, but I thought it made the script cleaner.

Using if and elseif I run through the three possible text strings to establish the rating. And finally I print the results along with a link to the entry describing my movie rating system. Don’t forget: your web page needs to have the extension ‘php’ for this to work.

Any comments or suggestions can be emailed to me and I will update this entry as needed.