howto_user (howto_user) wrote in s2howto,

[paid accounts only] [haven] Adding a tag cloud to the sidebar

Paid Accounts Only
The following tutorial requires creating and editing a custom style, which in turn requires a paid, permanent, or early adopter account. Please read What are the paid account benefits? and How do I buy a paid account? to learn about the paid account benefits and how to buy a paid account.

This tutorial will explain how to add a tag cloud to the sidebar in the Haven layout. The code will need to be placed into a theme layer, as it will override the function print_sidebar(). If you already have a theme layer, you will need to edit it and add the code below. If you do not have a theme layer, you will need to create one by following the instructions in the Theme Layer tutorial.

A tag cloud is a list of your tags, where the size of the font is proportional to the number of times the tag has been used. In the Haven layout, you can add a tag cloud into an extra sidebar box using the code below. The parts highlighted in green are the minimum and maximum font sizes in pixels to use for the cloud and these can be changed as you wish. For information on changing the order of the sidebar boxes, or for creating new sidebar boxes, you can follow this tutorial. Note that if your theme layer already has function print_sidebar(), you will need to modify it to include the code highlighted in orange. Otherwise, copy and paste the following code into the layer, making sure to include everything:

function print_sidebar()

var int minSize = 12; var int maxSize = 24; var Page p = get_page(); var TagDetail[] visibletags = $p->visible_tag_list(); if (size($visibletags) != 0 and $p.view != "friends") { var string taglist_title = "<br /><b>Tags:</b>"; var string taglist = ""; var int count = 1; foreach var TagDetail t ($visibletags) { if ($t.use_count > $count) { $count = $t.use_count; } } foreach var TagDetail t ($visibletags) { var int tagSize = $minSize; if ($t.use_count > 1) { $tagSize = (($maxSize-$minSize)*$t.use_count)/$count + $minSize; } $taglist = $taglist + """<a href="$t.url" style="font-size: """ + $tagSize + """px;">$</a> """; } print_sidebar_box($taglist_title, $taglist); }

This code will add a tag cloud to the sidebar in all journal views except the friends view. If you would like to see your tag list also on your friends page, remove the text highlighted in yellow.

Compile your layer, and it's ready to use. You will need to apply your theme layer via the Customize interface in order for your changes to take effect.

Contributed by scaryjeff, based on tutorials by camomiletea and tell_me.

Tags: - haven, paid accounts only, tag cloud

Comments for this post were disabled by the author