How to get a year list of entries in ExpressionEngine?

So, 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: http://cl.ly/image/0T1M0j1p0R3f

thanx


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}

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

链接地址: http://www.djcxy.com/p/66024.html

上一篇: expressionengine将不会显示所有条目

下一篇: 如何获得ExpressionEngine中的条目年份列表?