Hit or Miss

Weighted Categories for Movable Type

So as not to leave out my MovableType brethren, I adapted my Weighted Categories WordPress plugin for use on MT (to get a list of categories that looks like Flickr’s photo tag list).

This is a PHP script rather than a standalone plugin, but it gets the job done.

Because I can’t predict the number of categories you have on your blog (or the number of entries in each category), you’ll probably want to adjust the CSS and font-sizes to get the list to look the way you want.

If you want to filter out certain categories from appearing in the list, try the Filter Categories Plugin.

The following code should be pasted into a MT Template (ex, your Master Archive Index). The output file must have a .php extension (and obviously, your server must support PHP for it to work).

body { font-family: arial; font-size: medium; }
#WeightedCategories { border: 1px solid #ccc; background-color: #eee; padding: 10px;
	width: 500px; text-align: left; }
#WeightedCategories a { text-decoration: none; }
Weighted Categories
<div id="WeightedCategories">
	$minfont = 12;
	$maxfont = 48;
	$fontunit = "pt";
	$catlinks{"<$MTCategoryLabel$>"} = "<$MTCategoryArchiveLink$>";
	$counts{"<$MTCategoryLabel$>"} = <$MTCategoryCount$>;
	$spread = max($counts) - min($counts); if ($spread <= 0) { $spread = 1; };
	$fontspread = $maxfont - $minfont;

	$fontstep = $spread / $fontspread; if ($fontstep <= 0) { $fontstep = 1; };
	foreach ($counts as $catname => $count)
		$catlink = $catlinks{$catname};
		print "<a href="$catlink" title="$count entries" style="font-size: ".
		($minfont + ($count/$fontstep))."$unit;">$catname</a> &nbsp;n";

2 responses so far (Respond)


Weighted Category Lists

After a few site tweaks earlier in the week allowed me to implement new categories in this weblog, I decided to add weighted category lists, much like Flickr & Technorati. I modified an example given by hitormiss, which looks like…

Nedward | 7 Feb 2005

[…] modified an example given by hitormiss, which looks like this: <?php $minfont = 1; $maxfont = 5; $fontunit = ""; […]

Weighted Category Lists at //nedward.org | 5 Aug 2008