We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Grouping Channel Entries by Year and Displaying Year Only Once

Development and Programming

Richard Whitmer's avatar
Richard Whitmer
96 posts
about 8 years ago
Richard Whitmer's avatar Richard Whitmer

I’m on EE 3.5.6 and need to:

  1. Return a paginated list of channel entries grouped by year.
  2. Display the year only once at the beginning of each set of results within that year.
  3. Display data from custom fields from each entry.

So far, I’ve come up with two ways to do this or to get close.

  • CSS/JS that removes all but the first occurrence of each year from the DOM.
  • Using a yearly archive plugin and calling an embedded template that lists only entries for the embedded year.

The embedded solution doesn’t really let me paginate like it should be paginated and, since there are a lot of entries, adds many queries and page load time. The DOM solution is alright, I suppose, but I’m wondering if there’s a better solution; preferably without enabling PHP in the template.

Thanks.

       
Jeremy S.'s avatar
Jeremy S.
353 posts
about 8 years ago
Jeremy S.'s avatar Jeremy S.

I am assuming, since you mentioned a plugin, you looked at Low’s Yearly Archives already? http://gotolow.com/addons/low-yearly-archives

From the most basic view, have you looked at the channel entry variable date_heading, i.e. {date_heading display=”yearly”)

https://docs.expressionengine.com/latest/channel/channel_entries.html

{exp:channel:entries
        channel="channel_name"
 status="open"
 date_heading display="yearly"
 limit="xx"
 }
       
Richard Whitmer's avatar
Richard Whitmer
96 posts
about 8 years ago
Richard Whitmer's avatar Richard Whitmer

Excellent. The date_heading variable pair accomplishes exactly what I needed without an embed or DOM scripting. Thanks, Jeremy.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.