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


