Search code examples
expressionengine

How to get a year list of entries in ExpressionEngine?


I need to get list of years of all entries for use in dropdown. Basically I need to group entry date by year and output grouped year in a list.

something like this: https://dzwonsemrish7.cloudfront.net/items/2G161x0v1U0d2U0k133a/2012-10-23_19-50-41.jpeg?v=9c5b44e8


Solution

  • This addon for EE1 or EE2 will get you what you need: http://devot-ee.com/add-ons/yearlist

    {exp:yearlist channel="yourchannel"}
             <a href="{path=archive}/{year}">{year}</a>
    {/exp:yearlist}
    

    Then in your template limit the entries with the year="" parameter:

    {exp:channel:entries channel="news" year="{segment_2}"}
        <h1>{title}</h1>
        {body}
    {/exp:channel:entries}