I blog mostly my dreams and funny stories. I thought it would be interesting to create a Tag Cloud to display the topics I most often write about. It would show the things I most often dream or think about. The thought bubble on the right side of this page displays the most commonly-used words in the content of my website (excluding common words from the English language). It is a Joomla! Tag Cloud module, based on code from AkoCloud, but with major design and functionality changes.
Basically, the way AkoCloud works is by retrieving every content item's header text, main body text and title. It combines them and removes the most common words (which it references in mod_akocloud_wordlists.php) and counts the occurrences of the remaining words. It then displays the most frequently used words on your webpage.
There were a number of issues that I wanted to improve and customize for my own website:
{google_extensions}
Removing Words From The Exclude List
This was very simple, yet a little time consuming. I opened mod_akocloud_wordlists.php and removed all of the words I might expect to see on my site from the array of common English words. It was a monotonous task but didn't take more than five or ten minutes.
Including The Title Alias, Meta-Description and Meta-KeywordsThis was fairly straightforward, except that for some reason the database call would not complete while the new query parameters (title_alias, metadesc, metakey) were in single quotes. They had to be left out of quotes while title, introtext and fulltext were left in single quotes.
Then for each returned row, the new query results had to be added to the list of words to be processed:
I noticed that words like "dream", "dreams", "dreamed" and "dreaming" were appearing in the cloud. I wanted to combine all forms of a single word into a singular or present-tense form so that the most commonly used words wouldn't be diluted. Combining them to a single form would make the Tag Cloud better reflect the actual content on my website.
The implementation was simple. The AkoCloud code was already performing some string replacement for non-alphanumeric characters, like "<", ">", "!", ".", etc. I added several more lines to remove plurals, "es", past-tense, "ed", and present-tense action, "ing" (this would add a considerable amount of processor time to the module, but I would address that later with a caching system):
I also added a few lines for scenarios where certain words were getting an extra letter removed or just needed to be changed:
I noticed that a few words were appearing far too often on my website, like "dream". Its tag count was so much higher than the rest of the tags that it was very large, and the rest of the tags were very small with little distinction in size. To fix this, I needed a way to set a size limit on tag count. I set a module parameter that I could adjust in the Joomla! Backend, $maxhitcount. While the final array of tags and their counts are compiled, I check the tag count's size. If it is not less than the $maxhitcount then it isn't incremented:
This keeps an even distribution of tag count size and makes it look more like a cloud.
The next issue to tackle was the amount of processing time the module was using, especially with the last string replacement code snippet I had added. I decided the best implementation would consist of caching just the final output HTML for the tags,not the outer divs or styling. It now writes this string to a file so in the future it could be read in instead processing the query results for six fields of every content item in the database every time a visitor views a page.
Now when the module would run, it would first check the time that the text file was last modified. If the modified time was less than a certain number of hours (default of 24 hours) then it would spit out the HTML contents of that file. If it was older then it would recreate the string, save it to the file, and write it to the webpage:
I wanted to put the tag cloud in a thought bubble over a silhouette of myself, as if a website visitor was actually reading my thoughts. Well that's pretty close to the truth, as I currently have close to ninety dreams posted for the world's reading pleasure.
To create the bubbly cloud background image, I created a series of white circles in Photoshop. After getting them all lined up and merged onto the same layer I created a Layer Style with a Stroke 2px thick. Then I cut the image into three pieces, a top, middle and bottom, so that the middle piece could be tiled vertically to match the top and bottom, followed by the silhouette image. Here is the code that is echoed before and after the tags:
And the corresponding CSS:
I added a few parameters to the module so I could have more control over it from the Joomla! backend.
The finished product is a more resource-efficient, robust, and stylish implementation of a Tag Cloud, which can be seen to the right of every page on this website.
{google_extensions}
Download
Login and download from the Download page .
SupportPlease post all questions, comments, feature requests and bug reports to the JoomlaDigger.com forums:
Most Diggs Module Support Forums
All credit goes to the original AkoCloud module, which can be downloaded from http://www.konze.de.
I'm putting together a comprehensive training program to teach you everything you need to know about building websites with Joomla. Using the knowledge, tips and tricks I've learned over the last several years, I will teach you how to quickly create beautiful Joomla websites, avoid time-consuming web development pitfalls, make money with your site, and much more. Please take 3 minutes to tell me exactly what you want to learn about.
Copyright © 2007-2009 JoomlaDigger.com. All rights reserved. Website by P.J. Swesey. Owned and operated by Emergination, LLC.