Blog Archives Macro

Last modified by Andreea Popescu on 2021/03/17 21:27

cogViews blogs published in the last X months
TypeDoc (Velocity Macro)
Category
Developed by

Djebloun Sidali

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

This is for the old Blog application that was bundled with the default XWiki Enterprise XAR. We now have a new Blog Application that is offering such a macro in addition to an already made Panel too.

#macro(BlogArchives $spaceApplicationBlog $viewerBlogsResulting $nbrMonths)

#set($months = ["Foo","Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"])
#set($results=$xwiki.search("select year(doc.creationDate), month(doc.creationDate), count(doc) from XWikiDocument doc,
BaseObject as obj where obj.name=doc.fullName and doc.web='$spaceApplicationBlog' and obj.className='XWiki.ArticleClass'
group by month(doc.creationDate) order by year(doc.creationDate) desc",$nbrMonths,0))
#set($docYear=".")
#foreach ($row in $results)
  #foreach ($col in $row)
    #if ($velocityCount==1 && $docYear!=$col)
      #set($docYear=$col)
      * $docYear
    #elseif ($velocityCount==2)
      #set($docMonth=$col)
    #elseif ($velocityCount==3)
      #set($count=$col)
    #end
  #end
  ** <a href='$xwiki.getURL("$viewerBlogsResulting","view","curDate=${docMonth}-${docYear}")'>$months.get($docMonth) ($count)</a>
#end

#end

Usage

#BlogArchives($spaceApplicationBlog $viewerBlogsResulting $nbrMonths)

Parameters definition

NameOptionalAllowed valuesDefault valueDescription
$spaceApplicationBlognoa stringnonea space application blog
$viewerBlogsResultingnoa stringnoneViewer blogs resulting
$nbrMonthsnoa intnoneNumber of months to display

Example

#BlogArchives("Space_MySpace_Blog" "Space_MySpaceCode.displayByDate" 7)

Result

Exemple.png

Get Connected