tags component modifications

Sep 02, 2006 03:16

The new Tags component was a little too long for me with each tag on a new line. Instead, I wanted a comma-separated list; here's the code for it, if anyone else wants it. (Thanks to kunzite1 for a bit of coding help) :)

##############################
# CUSTOMIZING THE TAGS COMP. #
#        gameboyguy13        #
#   component-help/1074950   #
#         overrides:         #
#     print_tags(Page p)     #
##############################
function print_tags(Page p) {
    print_comp_header($*tags_text); #this is controlled by "Tags List Component Title" in the cust wizard; it can also be set by "set tags_text = "Tags";"
    var TagDetail[] tags = $p->visible_tag_list();
    var int tcount = 0;
    foreach var TagDetail td ($tags) {
        $tcount++;
        var string uses = get_plural_phrase($td.use_count, "text_tag_uses");
        var string security = $td.visibility;
        """ $td.name""";
        if($tcount < size($tags)) { print ", "; } #change the comma if you want to change the divider between tags
    }
    print_comp_footer();
}

And after thinking a bit, I thought, hey, Expressive gets a tag cloud; I wonder if I can adapt that code to Component? I've tested it a fair amount, but let me know if something doesn't work right.

################################
#   ADDING A TAG CLOUD v1.1    #
#         gameboyguy13         #
#    component-help/1074950    #
#          Overrides:          #
#      print_tags(Page p)      #
# code adapted from Expressive #
################################
function print_tags(Page p) {
    var bool opt_tag_limit = false; #Make this "true" to only display the first tag_limit tags.
    var int tag_limit = 0;
    print_comp_header($*tags_text);
    var TagDetail[] total_tags = $p->visible_tag_list();
    var int most_count = 1;
    if (size($total_tags) < 1) { print_comp_footer(); return; }
    var TagDetail[] tags;
    var int tcount = 0;
    foreach var TagDetail td ($total_tags) {
      if (($opt_tag_limit and $tcount < $tag_limit) or not $opt_tag_limit) {
        $tags[$tcount] = $td;
        $tcount++;
      }
    }
# First get the highest tag count there is
    foreach var TagDetail td ($tags) {
        if ($td.use_count > $most_count) {
            $most_count = $td.use_count;
        }
    }
# Now print the tag cloud
    foreach var TagDetail td ($tags) {
        var string uses = get_plural_phrase($td.use_count, "text_tag_uses");
        var string security = $td.visibility;
        var int tagtextsize = 7;
        if ($td.use_count > 1) {
            $tagtextsize = ($td.use_count * 16) / $most_count + 7; # Text size, in pixels, of this tag -- min is 7px, max is 23px. It's possible to change the numbers to play with the sizes, if you want.
        }
        """ $td.name """;
    }
    print_comp_footer();
}

user: gameboyguy13, !tutorial, function: print_tags, *account level: paid/perm

Previous post Next post
Up