Building a Weighted Category List


Published on December 27, 2004 at 2:05 PM EST
In the Tutorials category.

A while ago I read What’s this blog about?, which showed a weighted list of keywords that appears on his site. I thought that was a cool idea, to show—based on font size—the most written-about topics. What I put together…

A while ago I read What’s this blog about?, which showed a weighted list of keywords that appears on his site. I thought that was a cool idea, to show—based on font size—the most written-about topics.

What I put together isn’t anywhere near that complex. The weighted category list simply assigns a font size to the category name based on the number of entries associated with that category. Here’s a snapshot of danandsherree.com’s weighted category list:

About Dan (Old Stuff) Boy Scouts Christmas Computers Crafts danandsherree.com News Elsewhere in our Life Girl Scouts Movable Type Music, Movies and Television Photography Pinball the Cat Random News Bits RC Cars Reviews Travelogues and Photos Work-Related

Below is the code I used to build that list. You’ll need to be able to use PHP to use this, and it’ll have to go into an Index Template to work.

<p>
<MTCategories show_empty="1"><?php

// Set the number of entries required to jump a font size.
$a = 5;
$b = 10;
$c = 15;
$d = 20;
$e = 25;
$f = 30;
$g = 40;

if (<MTCategoryCount> <= $a ) {
 echo '<span style="font-size: 75%;"><a href="<MTCategoryArchiveLink>" title="<MTCategoryDescription remove_html="1" encode_php="q">"><$MTCategoryLabel$></a></span> ';

} elseif (<MTCategoryCount> <= $b ) {
 echo '<span style="font-size: 100%;"><a href="<MTCategoryArchiveLink>" title="<MTCategoryDescription remove_html="1" encode_php="q">"><$MTCategoryLabel$></a></span> ';

} elseif (<MTCategoryCount> <= $c ) {
 echo '<span style="font-size: 125%;"><a href="<MTCategoryArchiveLink>" title="<MTCategoryDescription remove_html="1" encode_php="q">"><$MTCategoryLabel$></a></span> ';

} elseif (<MTCategoryCount> <= $d ) {
 echo '<span style="font-size: 150%;"><a href="<MTCategoryArchiveLink>" title="<MTCategoryDescription remove_html="1" encode_php="q">"><$MTCategoryLabel$></a></span> ';

} elseif (<MTCategoryCount> <= $e ) {
 echo '<span style="font-size: 175%;"><a href="<MTCategoryArchiveLink>" title="<MTCategoryDescription remove_html="1" encode_php="q">"><$MTCategoryLabel$></a></span> ';

} elseif (<MTCategoryCount> <= $f ) {
 echo '<span style="font-size: 200%;"><a href="<MTCategoryArchiveLink>" title="<MTCategoryDescription remove_html="1" encode_php="q">"><$MTCategoryLabel$></a></span> ';

} elseif (<MTCategoryCount> <= $g ) {
 echo '<span style="font-size: 250%;"><a href="<MTCategoryArchiveLink>" title="<MTCategoryDescription remove_html="1" encode_php="q">"><$MTCategoryLabel$></a></span> ';

// Really big category!
} else {
   echo '<span style="font-size: 300%;"><a href="<MTCategoryArchiveLink>" title="<MTCategoryDescription remove_html="1" encode_php="q">"><$MTCategoryLabel$></a></span> ';
} ?>

</MTCategories>
</p>

This is obviously some very simple code. The variables $a through $g are compared against the number of entries in a category. You’ll probably want to change them to reflect your site. Specifically, $a should be a little bigger than your smallest cateogry and $g should probably be a bit bigger than your largest. So, for a larger site something like this might be better:

$a = 15;
$b = 30;
$c = 45;
$d = 60;
$e = 75;
$f = 90;
$g = 105;

It’s probably also worth pointing out that there’s an “overflow” in the above, for if your site grew and you didn’t remember to change the variable (“//Really big category!”).

I think I picked some ok font sizes, but it’s easy enough to change them—look at the style="font-size: <Percent>%; pieces. Just change the Percent number to something you like.

This article is tagged as: Template Tags, Tutorials

Comments

So far, there are 12 comments and Trackbacks on this entry. Add yours!

1

Very cool!

2

http://www.danandsherree.com/2004/12/27/building_a_weighted_.php…

3

Gewichtetet Stichwortlisten sind Besuchern von Flickr sicher bekannt. Die 150 beliebtesten Tags der Benutzer sind auf dieser Seite zusammengefasst. In What’s this blog about? zeigt Adam Kalsey, welche Stichwörter in…

4

The sidebar of this weblog shows an example. The TypePad team send me this:

5

We’ve just released the Tags plugin for Movable Type as part of our Power Tools collection, and there’s an accompanying interview with Brad Choate which covers some of his thoughts on creating the plugin. The Tags plugin meets the needs…

6

Is this also possible for TypePad users. I have a Pro account. And if so how can I do that?

7

A couple of months ago I wrote about how I wasn’t too crazy about podcasting and tagging. Although I haven’t completely changed my mind on the matter I have warmed up to tags enough to incorporate them into my site….

8

Easy instructions for building a weighted tag cloud in Movable Type, based on categories. I wish it was as easy to do with keywords, rather than categories, as assigning multiple categories can sometimes be a bit of a hassle….

9

I’m hoping I’ll be able to figure out how to use this. I want to show which of the Tags I have for a certain page is the one that is most popular when compared to other tags(categories) for that entry.

10

Building a Weighted Category List | Eat Drink Sleep Movable Type…

11

12

Really a cool idea, does it look like the tag wordpress plugin?

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

 
 
 


TrackBack URL for Building a Weighted Category List:
http://www.eatdrinksleepmovabletype.com/cgi-bin/mt/mt-tb.cgi/217