PixyBlog Lightbox   |   Basket   |   Login   |   Register
Pixy® Blog - Expose Yourself
  PixyBlog.comPhotoblog DiscussionPhotoblog Wiki
  • Log in / create account
Creating a monthly archive list
  • Page
  • Discussion
  • View source
  • History

Creating a monthly archive list

From PixyWiki

Jump to: navigation, search

This article is adapted from this post by Wayne Horkan.

Many blogs display a list of months that when clicked show the posted entries for that month.

Here's an example using our News Blog:

  • » June, 2009
  • » May, 2009
  • » April, 2009
  • » March, 2009
  • » February, 2009
  • » January, 2009
  • » December, 2008

This can be achieved using the following velocity code:

## Blog Start Year
#set ($startYear  = 2006)

## Blog Start Month
#set ($startMonth = 5)

## Get the current Year and Month
#set ($countYear  = $utils.now.getYear() + 1900)
#set ($countMonth = $utils.now.getMonth() + 1)

## Text Adjust

#set ($zero = 0)

## Total number of years to cycle through
#set ($numberYear  = $countYear - $startYear)

<ul class="rEntriesList">

#foreach ($number in [0..$numberYear])

  #if ($countYear >= $startYear)

    ## Months in a year
    #foreach ($number in [1..12])

      #if  (($countMonth != 0) && ((($countYear > $startYear) || (($countYear == $startYear) && ($countMonth >= $startMonth)))))

        <li class="recentposts">

        #if ($countMonth     ==  1)
          #set ($nameMonth = "January")
        #elseif ($countMonth ==  2)
          #set ($nameMonth = "February")
        #elseif ($countMonth ==  3)
          #set ($nameMonth = "March")
        #elseif ($countMonth ==  4)
          #set ($nameMonth = "April")
        #elseif ($countMonth ==  5)
          #set ($nameMonth = "May")
        #elseif ($countMonth ==  6)
          #set ($nameMonth = "June")
        #elseif ($countMonth ==  7)
          #set ($nameMonth = "July")
        #elseif ($countMonth ==  8)
          #set ($nameMonth = "August")
        #elseif ($countMonth ==  9)
          #set ($nameMonth = "September")
        #elseif ($countMonth == 10)
          #set ($nameMonth = "October")
        #elseif ($countMonth == 11)
          #set ($nameMonth = "November")
        #elseif ($countMonth == 12)
          #set ($nameMonth = "December")
        #end

        #if ($countMonth > 9)
          <a href="$url.page("Blog")?date=$countYear$countMonth">» $nameMonth, $countYear</a>
        #else
          <a href="$url.page("Blog")?date=$countYear$zero$countMonth">» $nameMonth, $countYear</a>
        #end

        </li>

        #set ($countMonth = $countMonth - 1)

      #end
 
    #end

  #set ($countMonth = 12)

##</ul>

  #end

#set ($countYear = $countYear - 1)

#end

Note: change the values of $startYear and $startMonth to reflect that of your blog.

Retrieved from "http://wiki.pixyblog.com/Creating_a_monthly_archive_list"
This page was last modified 10:31, 2 June 2009. This page has been accessed 146 times.
  • Privacy policy
  • About PixyWiki
  • Disclaimers
  • Powered by MediaWiki
  • Design by Paul Gu
Terms and Conditions | Privacy Policy | About | Contact us | Copyright © 2006-2008 Pixy® Ltd. All rights reserved.