<< Home

Monday, December 1, 2008

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):

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 -->');
}

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> ";
}

The complete file can be downloaded here. Follow these steps to set it up and running:
  1. Copy the script to the root folder of your blog.
  2. Modify the SEARCH_DIR define in line 4 to suit your setup.
  3. Create a directory called cloudtemp in the ./labels directory of your root folder:
    # mkdir labels/cloudtemp
  4. Add the directive
    AddType application/x-httpd-php .html
    to your VirtualHost file, e.g. to the section.
  5. Reload your apache server:
    # /etc/init.d/apache2 reload
  6. 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: , ,


8 Comments:

Anonymous Thomas Powell said...

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.

January 10, 2009 12:41 PM  
Blogger dengar.lihat.rasahati said...

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~

February 19, 2009 7:53 AM  
Anonymous Anonymous said...

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

November 8, 2009 6:26 PM  
Blogger fwJL said...

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?

November 9, 2009 7:35 AM  
Anonymous Anonymous said...

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!

November 14, 2009 5:46 AM  
Anonymous Anonymous said...

blog.alphagemini.org is very informative. The article is very professionally written. I enjoy reading blog.alphagemini.org every day.
fast loans payday

November 23, 2009 2:09 PM  
Anonymous Anonymous said...

This blog is great! Thanks for your hard work on it.

December 30, 2009 11:37 AM  
Anonymous Anonymous said...

Thank you so much for your siteI love everything about it.

January 1, 2010 11:47 AM  

Post a Comment