Movable Type has become one of the first platforms in which tags have appeared . It happened in the third version. And in the fourth version it is possible to add tags not only to post, but also to uploaded files or created pages. But functionality of the tag MTTags is not thought over up to the end in the current version as well as in the previous version MT. It is necessary to make some efforts to have a normal Tag Cloud.
In the third version it was possible to deduce the list of all tags, excepting an opportunity of restriction of their numbers. The cloud was expected to turn out. When tags became more, they turned into a cloud and occupied the most part of the screen.
In the fourth version an opportunity has been added to establish the numbers of displayed tags, and also their sorting by ranks. Now on the site it's possible to show a cloud which will include 50 of the most popular tags. The numbers of tags in a cloud is set individually, but such opportunity pleases. But there’s an ill luck: when sorting by ranks tags are displayed in this way — the more popular the tag is, the higher it will be, or on the contrary. A simple example:
It does not suit at all as the visual perception of such cloud does not cause any desire to click under the link. Therefore it is necessary to resort to PHP’s help.
Create Normal Tags Cloud
- First of all you must change extension of files on .php. For this just go to the settings of the blog, then to the tab “Publishing”. Enter “php” near by the item “File Extension for Archive Files” (without a point in the beginning). After that all archives (posts, categories, pages, etc) will be published with new extension. But some index files, for example, Main Index and Archives, will stay with old extensions. Therefore you will have to go to the section Templates and manually specify the necessary extension for these templates.
- Then it is necessary to create an index tempalate (we call it TagCloud, with a name of the published file tagcloud.php) which will be automatically published with the following contents:
Download the example with the comments.
$tagslist = array(<MTTags limit="50" sort_by="rank" glue=", ">"<$MTTagName$>" => <$MTTagRank max="10"$></MTTags>);
while (list($tag, $tagsize) = each($tagslist))
echo '<a href="http://example.com/tag/'.rawurlencode($tag).'" class="t'.$tagsize.'" rel="tag">'.$tag.'</a>';
- If you want template TagCloud to be displayed on other pages of the site you should include it in these pages. It is made with the help of function include in PHP:
<? include ("/home/user/example.com/template-path/tagcloud.php"); ?>
If you have standard templates this line is necessary to be set in a Sidebar template (“Sidebar (3-column)” or “Sidebar (2-column)”). Find a code <MTTags limit ="20" sort_by ="rank"> finishing with </MTTags>. Delete it and interchange it with a line from the third point. Pay attention that you must specify an absolute way to a template. You can learn about if you look in the blog settings.
Well that’s all, now you should have normal Tags Cloud or something like this:
- Everybody loves tags!
Look at the point “Beautifying the tag search link URLs” and learn how to make beautiful URL for tags.
Thanks Zara Khudaverdyan for the help in translation of tutorial into English language.
This tutorial on Russian language.