classic template tag cloud
Since I'm hosting this blog on my own server I'm not able to use the blogger's new "Layouts customization" and thus can't display these fancy tag clouds which usually appear in the sidebar. However, I've found some solutions which add labels functionality to classic blogger templates, the most flexible of which seem to be using a PHP script which can be used in the template. So I've modified the script found on this blog, fixing a minor bug and adding two new features. First, the script now takes care of the actual amount of tagged articles under a certain label which can optionally be displayed next to the label (check the second source code snippet and uncomment the appropriate lines):
Second, result pages invoked from links in the label cloud now correctly link to other results by conditionally removing the prefix to the label directory:
The complete file can be downloaded here. Follow these steps to set it up and running:
if(preg_match("/\/labels\//", $_SERVER['PHP_SELF'])) {
$files[$file] = substr_count(
file_get_contents($file),'<!-- End .post -->');
} else {
$files[$file] = substr_count(
file_get_contents(PREFIX.$file),'<!-- End .post -->');
}
$files[$file] = substr_count(
file_get_contents($file),'<!-- End .post -->');
} else {
$files[$file] = substr_count(
file_get_contents(PREFIX.$file),'<!-- End .post -->');
}
Second, result pages invoked from links in the label cloud now correctly link to other results by conditionally removing the prefix to the label directory:
if(preg_match("/\/labels\//", $_SERVER['PHP_SELF'])) {
$output .= "<a style=\"".
get_style($low_end, $high_end, $size) . "\"".
"href=\"". htmlentities($name)."\">".
# Uncomment the next and comment the following line in order
# to display the number of posts for each given label.
#htmlentities(str_replace('.html','',$name))."(".$size.")</a> ";
htmlentities(str_replace('.html','',$name))."</a> ";
} else {
$output .= "<a style=\"".
get_style($low_end, $high_end, $size) . "\" ".
"href=\"".PREFIX. htmlentities($name)."\">".
# Uncomment the next and comment the following line in order
# to display the number of posts for each given label.
#htmlentities(str_replace('.html','',$name))."(".$size.")</a> ";
htmlentities(str_replace('.html','',$name))."</a> ";
}
$output .= "<a style=\"".
get_style($low_end, $high_end, $size) . "\"".
"href=\"". htmlentities($name)."\">".
# Uncomment the next and comment the following line in order
# to display the number of posts for each given label.
#htmlentities(str_replace('.html','',$name))."(".$size.")</a> ";
htmlentities(str_replace('.html','',$name))."</a> ";
} else {
$output .= "<a style=\"".
get_style($low_end, $high_end, $size) . "\" ".
"href=\"".PREFIX. htmlentities($name)."\">".
# Uncomment the next and comment the following line in order
# to display the number of posts for each given label.
#htmlentities(str_replace('.html','',$name))."(".$size.")</a> ";
htmlentities(str_replace('.html','',$name))."</a> ";
}
The complete file can be downloaded here. Follow these steps to set it up and running:
- Copy the script to the root folder of your blog.
- Modify the SEARCH_DIR define in line 4 to suit your setup.
- Create a directory called cloudtemp in the ./labels directory of your root folder: # mkdir labels/cloudtemp
- Add the directive AddType application/x-httpd-php .htmlto your VirtualHost file, e.g. to the
section. - Reload your apache server:# /etc/init.d/apache2 reload
- If you'd like to display the number of related articles in brakets behind the label's name just follow the directives in lines 52 and 60.
Labels: blogging, curiosities, php

8 Comments:
Good to see that somebody was able to take something I threw together quickly and put it to good use. I wanted to do something other than rely on file size, but it wasn't important enough to me to ever make that improvement.
ouh.great.
have been searching for label cloud codings..since i'm using classic template for blogger.
could you help me with this?
can i put that label cloud [like yours] in my blog?i've tried.i've copied those codes u wrote on this post but it didn't work. why? and how to fit them in mine? i'm looking forward to learn how.
thanks.
sharing is caring~
I found this site using [url=http://google.com]google.com[/url] And i want to thank you for your work. You have done really very good site. Great work, great site! Thank you!
Sorry for offtopic
hi, i'm really appreciative that u had this tag cloud HTML codings for classic templates. but the problem is, i can't get to download the file, and also i don't really understand how to do it, since i'm a HTML amateur. any way to explain it in a "HTML for dummies" way?
Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!
blog.alphagemini.org is very informative. The article is very professionally written. I enjoy reading blog.alphagemini.org every day.
fast loans payday
This blog is great! Thanks for your hard work on it.
Thank you so much for your siteI love everything about it.
Post a Comment