Taxonomy Weight Visualisation

Note: With the release of tagadelic module, this trick is no longer required.

The idea is to display ‘weight’ of taxonomy temrs like Flickr’s tag

The article.module already provide something along these line, displaying taxonomy hierachy as unordered list. So I hacked it (only a little) to get the result.

First, I added a specific class for the taxonomy listing


function theme_article_index(&$name, &$index_list) {
if ($index_list != “”) {
return “

\n$index_list\n

\n”;
}
return “”;
}

And then removed the print out of number of items in each taxonomy ($term->count), and instead use the value to calculate font-size to applied to the term’s name.


function theme_article_index_item(&$term) {
$description = ($term->description != “”) ? “

“. $term->description .”

“ : “”;
if ($term->count > 0) {
return “

  • count) .“px; \”>”. l($term->name, $term->link) .”

    “. $description.$term->children .”

  • “;
    }
    else {
    return “

  • “. $term->name .”

    “. $description.$term->children .”

  • “;
    }
    }

    I’m doing only a crude calculation (linear), but the parameter 12.3 and 0.19 can be tuned to suits different needs. It is about right for this site, but you might want to vary it a little.

    Then the last part is to collapse the list and run the taxonomy terms together, with CSS.


    .item-list-article {
    margin: 40px 15px;
    }

    .item-list-article ul {
    display: inline;
    padding: 0px;
    margin: 0px;
    }

    .item-list-article li {
    list-style: none;
    display: inline;
    padding: 0px 0.4em;
    margin: 0px;
    }
    .item-list-article .article-title { display: inline; }
    .item-list-article .article-desc { display: none; }