Weighted Category Lists at //nedward.org



Weighted Category Lists

After a few site tweaks ear­lier in the week allowed me to imple­ment new cat­e­gories in this weblog, I decided to add weighted cat­e­gory lists, much like Flickr & Technorati.

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

<?php
$min­font = 1;
$max­font = 5;
$fontu­nit = "";
<MTCategories>
$catlinks{"<$MTCategoryLabel$>"} = "<$MTCategoryArchiveLink$>";
$counts{"<$MTCategoryLabel$>"} = <$MTCategoryCount$>;
</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 classes — 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 couple 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 editor, which should work)

0 Responses to “Weighted Category Lists”


Comments are currently closed.