kunzite (kunzite1) wrote in s2layers,
kunzite
kunzite1
s2layers

[theme] - [component] - [tagcloud component]

in response to browneyedgirl65's component_help post.
var string      header      = "";
var string      content     = "";

var int         int_groups  =   5; # number of groups
var int         int_percent =  20; # perecentage difference for each interval

$header = "Category Cloud";

var int         adjust      = 0; # font size adjustment
var int         factor      = 0; # factor of font size adjustment
var int         interval    = 0; # tag use count interval per group
var int         max         = 1; # max number of tag uses
var TagDetail[] my_tags     = $p->visible_tag_list(); # list of visible tags

# implement cloudstyle ala delicious, etc
if ($my_tags) {
  $content = $content + """
  <table name="taglist" width="100%" cellpadding="3">
    <tr>
      <td>
  """;

  # get max
  foreach var TagDetail t ($my_tags) {
    if($t.use_count > $max) {
      $max = $t.use_count;
    }
  }

  # now we get tag use count interval per group
  $interval = $max / $int_groups;

  # now print each item, and adjust its
  # fontsize as a function of where in the
  # continuum of $int_groups intervals it is
  foreach var TagDetail t ($my_tags) {
    # if we're not going to divide by 0
    if($interval > 0) {
      # get the proportion based on use_count and interval
      $factor = $t.use_count / $interval;
    } else {
      # if we're dividing by 0, set factor to 0
      $factor = 0;
    }
    $adjust  = ($factor * $int_percent) + 100;
    $content = $content + """<span style="font-size: ${adjust}%"><a rel="tag" href="$t.url">$t.name</a></span> """;
  }
  $content = $content + """
      </td>
    </tr>
  </table>
  """;
} else {
  $content = $content + """<p>There are currently no tags or categories for this journal.</p>""";
}

print_comp_header($header);
print $content;
print_comp_footer();
Tags: function print_free_text, layout component
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded 

  • 28 comments