cogDisplays a Tag cloud
TypeSnippet
Category
Developed by

Thomas Devron

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

An easy-to-configure Tag Cloud representation of the tags used in an xwiki instance.

Using XWiki 1.8 and above

{{include document="XWiki.TagCloud"/}}

Using XWiki 1.7.x and below

The code snippet below uses a privileged api (xwiki.search()) and thus you'll need to have programming rights when you save this code snippet.

#set($query = "select elements(prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'")

#set( $allTags = $xwiki.sort($xwiki.search($query)))
#set( $previousTag = "")
#set( $tagsWithCount = $xwiki.getHashMap())
#set( $count = 1)
#set( $maxCount = 1)
#foreach($tag in $allTags)
  #if ($tag == $previousTag)
    #set( $count = $count + 1)
    #if ($count > $maxCount)
      #set ($maxCount = $count)
    #end
  #else
    #set( $count = 1)
    #set( $previousTag = "")
  #end
  #set( $dummy = $tagsWithCount.put($tag, $count))
  #set( $previousTag = $tag)
#end

#set($query = "select distinct elements(prop.list) from BaseObject as obj, DBStringListProperty as prop where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags'")

#set( $tagsDistinct = $xwiki.sort($xwiki.search($query)))
<div style="font-size: 2.00em; text-align: justify; text-justify: auto;">
#foreach($tag in $tagsDistinct)
  #set( $currentCount = $tagsWithCount.get($tag))
  #set( $size = 25 + ($currentCount * 90 / $maxCount))
 <span style="font-size: $size%"><a href="$xwiki.getURL("Main.Tags""view""tag=$tag")")>$tag</a></span>
#end
</div>

Result

screenshot_tagcloud.png

Tags: tag
     

Get Connected