The code in this tutorial will create tag clouds, which can be inserted into a box in the sidebar, or into the tag page. A
tag cloud is an alphabetised list of tags where the most commonly used tags are depicted in a larger font or otherwise emphasized.
To do that, the tags have to be divided into different categories according to their number of
(
Read more... )
The difference in size is something that you control anyway. Augment the increment and/or the number of categories :)
Here's the new tag cloud code (in green is what I changed):
#### TAG CLOUD CODE ####
###### Configuration ######
var int tag_category = 8; # The number can be changed if you want more or fewer categories.
var int basefontsize = 80; # size of the first tag category in percent of the default font size of the page.
var int increment = 50; # The difference in size between tag categories.
var string subject = "Tag cloud"; # Title of the tag page.
var int no_print_tag = 3 ; # Minimum number of uses of the tag for it to print.
###### End Configuration ######
var Page p = get_page();
var string list = "";
var int max_use_count = 0 ;
var int min_use_count ;
var int x ;
if (size $p->visible_tag_list() > 0)
{
# Define a maximum number of uses of the tags:
var TagDetail[] visible_tag_list = $p->visible_tag_list();
if($visible_tag_list)
{
foreach var TagDetail td ($p->visible_tag_list())
{
if ($td.use_count > $max_use_count)
{
$max_use_count = $td.use_count;
}
}
}
# Define the mimimum number of uses of the tags:
$min_use_count = $no_print_tag;
# Avoid a division by zero
if ($max_use_count == $min_use_count)
{
$max_use_count = $max_use_count + 1;
}
# Put the tags into categories according to the number of times they're used,
# then use it to determine the size of the tag:
foreach var TagDetail td ($p->visible_tag_list())
{
if ($td.use_count < $no_print_tag)
{
# Don't print anything
}
elseif ($td.use_count >= $no_print_tag)
{
# Create different categories according to the number of uses of the tag
$x = (($td.use_count - $min_use_count) * $tag_category / ($max_use_count - $min_use_count));
if ($x == $tag_category) { $x = $tag_category - 1; }
# Convert those categories into sizes
$x = ($x * $increment) + $basefontsize;
$list = $list + """ $td.name """;
}
}
# Enclose the entire list in a paragraph tag.
$list = """
""" + $list + """
""";
}
#### END TAG CLOUD CODE ####If you need more help, tell me :)
Reply
Reply
Reply
Leave a comment