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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With