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(${esc.dollar}tagMap = {})
${esc.hash}foreach(${esc.dollar}con in ${esc.dollar}dotcontent.pull("+structureName:Blogentry +live:true +(${esc.dollar}catQueryforTagCloud)",0,"modDate desc"))
		${esc.hash}foreach(${esc.dollar}tag in ${esc.dollar}con.tag)
			${esc.hash}if(! ${esc.dollar}tagMap.get(${esc.dollar}tag))
				${esc.hash}set(${esc.dollar}dummy = ${esc.dollar}tagMap.put(${esc.dollar}tag,1))
			${esc.hash}else
				${esc.hash}set( ${esc.dollar}count = ${esc.dollar}tagMap.get(${esc.dollar}tag) + 1)
				${esc.hash}set(${esc.dollar}dummy = ${esc.dollar}tagMap.put(${esc.dollar}tag,${esc.dollar}count))
			${esc.hash}end
		${esc.hash}end
${esc.hash}end

${esc.hash}${esc.hash}Sort tag count alpha, sortAlpha is a dotcms macro from DotCMSMacroWebApi
${esc.hash}set(${esc.dollar}tagSorted = ${esc.dollar}macro.sortAlpha(${esc.dollar}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">
${esc.hash}foreach(${esc.dollar}tag in ${esc.dollar}tagSorted)
	${esc.hash}set(${esc.dollar}tagCount = ${esc.dollar}tagMap.get(${esc.dollar}tag))
	
		${esc.hash}set(${esc.dollar}class = "xSmallTag")
		${esc.hash}if(${esc.dollar}tagCount > 15)
			${esc.hash}set(${esc.dollar}class = "xLargeTag")
		${esc.hash}elseif(${esc.dollar}tagCount > 10)
			${esc.hash}set(${esc.dollar}class = "largeTag")
		${esc.hash}elseif(${esc.dollar}tagCount > 5)
			${esc.hash}set(${esc.dollar}class = "mediumTag")
		${esc.hash}elseif(${esc.dollar}tagCount >=2)
			${esc.hash}set(${esc.dollar}class = "smallTag")
		${esc.hash}end
	<a href="&amp;tagCount=${esc.dollar}{tagCount}" class="${esc.dollar}class">${esc.dollar}tag</a>
${esc.hash}end
</div>