OK. For anyone interested, I'm posting the final code for my tag cloud written specifically for use with CMS Builder (and thanks to all the help from the Interactive Tools team getting the trickiest parts working).
To see a sample of how it looks the way I implemented it, see the attached JPEG image. I now believe there may be a better way to approach this whole thing (as I mention in my post here: http://www.interactivetools.com/forum/forum-posts.php?postNum=2230008#post2230008); however, this version still works well and is still a completely valid tag cloud method.
Anyway, here's the code. This example is set up in CMSB with a multi-section called "blog_content", a field for the tags called "tags", a viewer page called "blog.php", and a list page called "blog_list.php" . You'll need to change the items in red to match your CMSB configuration:
<style>
/*** tags style ***/
#tags a{
color: #777;
font:normal 13px/26px Segoeui, Arial, Verdana, serif;
text-decoration: none
}
#tags a:hover{
color: #444;
}
/*** TAGS - 10 font-size steps ***/
#tags a.t0{font-size: 11px}
#tags a.t10{font-size: 12px}
#tags a.t20{font-size: 16px}
#tags a.t30{font-size: 20px}
#tags a.t40{font-size: 20px}
#tags a.t50{font-size: 24px}
#tags a.t60{font-size: 24px}
#tags a.t70{font-size: 27px}
#tags a.t80{font-size: 27px}
#tags a.t90{font-size: 27px}
#tags a.t100{font-size: 27px}
</style>
<?php
$tagsToCount = array();
$sectionsToField = array('blog_content' => 'tags'/*, 'blog2_content' => 'tags'*/); //to draw tags from multiple sections remove php comment tags and add as shown, otherwise you can delete everything between and including these: /* */
foreach($sectionsToField as $sectionName => $fieldName) {
//get section records
$records = mysql_select($sectionName);
foreach ($records as $record) {
//turn field into an array of values
$tags = explode(",", @$record[$fieldName]);
// add tags to the count array
foreach ($tags as $tag) {
$tag = trim($tag);
if (!$tag) { continue; } // skip empty array values
if (array_key_exists($tag, $tagsToCount)) {
$tagsToCount[$tag]++; }
else {
$tagsToCount[$tag] = 1;
}
}
}
}
//PHP doesn't have a shuffle function built in that maintains keys, but this version does.
function shuffle_assoc($list) {
if (!is_array($list)) return $list;
$keys = array_keys($list);
shuffle($keys);
$random = array();
foreach ($keys as $key) {
$random[$key] = $list[$key];
}
return $random;
}
?>
<!-- DISPLAY TAGS -->
<?php $tagsToCount = shuffle_assoc($tagsToCount); ?>
<?php if ($tagsToCount): ?>
<aside id="tags">
<h3>Tags</h3>
<?php $maximumResults = 18;
$resultCount = 0;
?>
<?php $totalTagCount = array_sum($tagsToCount); ?>
<?php foreach ($tagsToCount as $key => $value): ?>
<?php
$ratio = (intval($value)/$totalTagCount) * 100; //get the number-of-tag-occurances as a percentage of the overall number
$ratio = round($ratio,-1); //round the number to the nearest 10
?>
<a class="t<?php echo $ratio; ?>" href="blog_list.php?tags_keyword=<?php echo $key;?>"><?php echo $key; ?></a>
<?php if (++$resultCount == $maximumResults) { break;}?>
<?php endforeach ?>
</aside>
<?php endif ?>
For a quick sample of how this could look in use on your page, you can add the following html:
<!-- Tags - SAMPLE -->
<aside id="tags">
<h3>Tags - Sample</h3>
<a class="t7" href="">design</a>
<a class="t3" href="">color</a>
<a class="t8" href="">web design</a>
<a class="t1" href="">computer</a>
<a class="t2" href="">ecommerce</a>
<a class="t9" href="">php</a>
<a class="t2" href="">html</a>
<a class="t6" href="">code</a>
<a class="t3" href="">logos</a>
<a class="t8" href="">letterhead</a>
<a class="t2" href="">branding</a>
<a class="t8" href="">print</a>
<a class="t4" href="">web</a>
<a class="t3" href="">freelance</a>
<a class="t5" href="">business</a>
<a class="t3" href="">store</a>
<a class="t10" href="">internet</a>
</aside><!-- #tags -->
Well, that's it! Have fun! If anyone chooses to modify it in the way I suggest in my previous forum post, I'd love to know and see what you come up with.
All the best!
- Jeremy
---------------------------
Dwelling Productions
www.dwellingproductions.com