Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions

List Publication Years in Menu


3 Posts   769 Views


14 June 2011 at 7:39am Community Member, 98 Posts

Hi All,

I have a news section in a site. What I would like to do in my template when viewing either the NewsList or individual News pages is replace my level 2 menu with a list of unique publication years ranging from the first article to the present.

My idea was to override the Menu method in my NewsList controller and change the output if $level == 2.

Could somebody help me out with the code that fetches the list of years and how I would make those links display all articles in a selected year when clicked.

Much appreciated!



15 July 2011 at 7:33am Community Member, 528 Posts

There is a GroupBy function which can be used, it helps is you sort your DataObject in the function which gets it otherwise you
'll get it in ID order

<% control GetNewsList.GroupedBy(Year) %>
<% control Children %>
<% end_control %>
<% end_control %>

This assumes GetNewsList() returns a list of News Items sorted by Date and that either you have a field called $Year or a getYear() function on your News Item DataObject. You really don't even need to override the Menu function just wrap the whole thing in a <% if Level(2) %>


12 October 2011 at 2:02am Community Member, 98 Posts

Managed to lose this thread and just find it again! Thanks @zenmonkey for letting me know about this very useful functionality.