Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 940
Davor Avatar asked Oct 24 '12 01:10

Davor


2 Answers

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}
like image 101
Anna_MediaGirl Avatar answered Jan 09 '23 00:01

Anna_MediaGirl


Using this add-on http://devot-ee.com/add-ons/yearlist you could do this:

Setup your dropdown like so:

<form name="yourform" action="">
    <select id="yourselect" name="yourselect">
        {exp:yearlist channel="yourchannel"}
            <option value="{path=archive}/{year}">{year}</option>
        {/exp:yearlist}
    </select>
</form>

On your landing page you'd do something like this to display your entries based on year:

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

And use some jQuery to redirect to your year pages:

<script type="text/javascript">
    $('#yourselect').change(function() {
        window.location = $(this).val();
    });
</script>

If you'd like to do it via javascript instead of jQuery checkout this article

like image 45
Natetronn Avatar answered Jan 09 '23 01:01

Natetronn