3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 532 Views |
-
List Publication Years in Menu

14 June 2011 at 7:39am
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!
Tim
-
Re: List Publication Years in Menu

15 July 2011 at 7:33am
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) %>
$Year
<% control Children %>
$Title
<% 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) %>
-
Re: List Publication Years in Menu

12 October 2011 at 2:02am
Managed to lose this thread and just find it again! Thanks @zenmonkey for letting me know about this very useful functionality.
| 532 Views | ||
|
Page:
1
|
Go to Top |


