Tag cloud by Structure and Categories

  • Created: Apr 08, 2013
  • Author: Greg Jordan
  • Company: Methodist Le Bonheur

Description

Tag cloud by Structure and Categories

Code

set($tagMap = {})
#foreach($con in $dotcontent.pull("+structureName:Blogentry +live:true +($catQueryforTagCloud)",0,"modDate desc"))
		#foreach($tag in $con.tag)
			#if(! $tagMap.get($tag))
				#set($dummy = $tagMap.put($tag,1))
			#else
				#set( $count = $tagMap.get($tag) + 1)
				#set($dummy = $tagMap.put($tag,$count))
			#end
		#end
#end

##Sort tag count alpha, sortAlpha is a dotcms macro from DotCMSMacroWebApi
#set($tagSorted = $macro.sortAlpha($tagMap.keySet()))
<style type="text/css" media="all">
.tagCloud .xSmallTag { font-size: .75em;  }
.tagCloud .smallTag { font-size: .95em; }
.tagCloud .mediumTag { font-size: 1.25em; }
.tagCloud .largeTag{ font-size: 2.0em; }
.tagCloud .xLargeTag{ font-size: 3.5em; }
</style>
<div class="tagCloud">
#foreach($tag in $tagSorted)
	#set($tagCount = $tagMap.get($tag))
	
		#set($class = "xSmallTag")
		#if($tagCount > 15)
			#set($class = "xLargeTag")
		#elseif($tagCount > 10)
			#set($class = "largeTag")
		#elseif($tagCount > 5)
			#set($class = "mediumTag")
		#elseif($tagCount >=2)
			#set($class = "smallTag")
		#end
	<a href="&amp;tagCount=${tagCount}" class="$class">$tag</a>
#end
</div>