Weighted Category Lists

After a few site tweaks ear­li­er in the week allowed me to imple­ment new cat­e­gories in this weblog, I decid­ed to add weight­ed cat­e­go­ry lists, much like Flickr & Tech­no­rati.

I mod­i­fied an exam­ple giv­en by hitormiss, which looks like this:

<?php
$min­font = 1;
$max­font = 5;
$fontu­nit = “”;
<MTCat­e­gories>
$catlinks{“<$MTCategoryLabel$>”} = “<$MTCat­e­go­r­yArchiveLink$>”;
$counts{“<$MTCategoryLabel$>”} = <$MTCat­e­go­ryCount$>;
</MTCategories>

$spread = max($counts) — min($counts); if ($spread <= 0) { $spread = 1; };
$fontspread = $max­font — $min­font;

$fontstep = $spread / $fontspread; if ($fontstep <= 0) { $fontstep = 1; };
fore­ach ($counts as $cat­name => $count)
{
$catlink = $catlinks{$catname};
print “<a href=\”$catlink\” title=\”$count entries\” class=\“cat”.
ROUND(($minfont + ($count/$fontstep))).”\”>$catname</a> &nbsp;\n”;
}
?>

[You can also down­load it in a text file]

Put it in your Move­able Type archive tem­plate, and you’re good to go. It will write 5 CSS class­es — cat1, cat2, cat3, cat4, cat5… (of course, you’ll have to define those in your stylesheet!)

You can head over to my archives page, to check out the imple­men­ta­tion. (Notice that the 5 largest cat­e­gories are the orig­i­nal 5… i will be clas­si­fy­ing old entries in the next cou­ple of days…)

(I apol­o­gize if not all the code is view­able here — I sug­gest you high­light and copy/paste to a text edi­tor, which should work)

0 Responses to “Weighted Category Lists”


Comments are currently closed.