{ column_width:57, column_count:13, subcolumn_count:0, column_gutter:17, align:'left' }



Weighted Category Lists

After a few “site tweaks”:http://ned.suckahs.org/archives/002706.php earlier in the week allowed me to implement new categories in this weblog, I decided to add weighted category lists, much like “Flickr”:http://www.flickr.com/photos/tags/ & “Technorati”:http://www.technorati.com/tag/.

I modified an example given by “hitormiss”:http://www.hitormiss.org/projects/weighted-categories-for-movable-type/, which looks like this:

==

<?php
$minfont = 1;
$maxfont = 5;
$fontunit = "";
<MTCategories>
$catlinks{"<$MTCategoryLabel$>"} = "<$MTCategoryArchiveLink$>";
$counts{"<$MTCategoryLabel$>"} = <$MTCategoryCount$>;
 </MTCategories>

$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\" class=\"cat".
ROUND(($minfont + ($count/$fontstep)))."\">$catname</a> &nbsp;\n";
}
 ?>

==

[You can also download it in a "text file":http://ned.suckahs.org/junkie/weighted_categories_template.txt]

Put it in your Moveable Type archive template, and you’re good to go. It will write 5 CSS classes — cat1, cat2, cat3, cat4, cat5… (of course, you’ll have to define those in your stylesheet!)

You can head over to my “archives”:http://ned.suckahs.org/monthly.php page, to check out the implementation. (Notice that the 5 largest categories are the original 5… i will be classifying old entries in the next couple of days…)

(I apologize if not all the code is viewable here — I suggest you highlight and copy/paste to a text editor, which should work)

0 Responses to “Weighted Category Lists”


Comments are currently closed.