Random archive posts in SiteVision


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #set ($propertyUtil = $sitevisionUtils.propertyUtil)
  2.  
  3. #if ($propertyUtil.getNode($portlet, 'menuRoot'))
  4.  
  5. #set ($rootNode = $propertyUtil.getNode($portlet, 'menuRoot'))
  6. #set ($random = $scriptUtil.getInstance("java.util.Random"))
  7. #set ($nodes = $rootNode.nodes)
  8.  
  9. #if (!$nodes.isEmpty())
  10. #set ($newnodes = [])
  11. #set ($looplen = $nodes.size())
  12.  
  13. #foreach ($foo in [1..$looplen])
  14. #set ($len = $nodes.size())
  15. #set ($len = $len - 1)
  16. #if ($len > 0)
  17. #set ($ix = $random.nextInt($len))
  18. #else
  19. #set ($ix = 0)
  20. #end
  21. #set ($thenode = $nodes.get($ix))
  22. #set ($dummy = $newnodes.add($thenode))
  23. #set ($dummy = $nodes.remove($ix))
  24. #end
  25.  
  26. #set ($nr = 0)
  27.  
  28. #foreach ($p in $newnodes)
  29.  
  30. #if ($nr < 5)
  31. $linkRenderer.update($p)
  32. $linkRenderer.setFontClass($fontClass)
  33.  
  34. $linkRenderer.render()
  35. #set ($nr = $nr + 1)
  36. #end
  37.  
  38. #end
  39.  
  40. #end
  41. #end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.