Hi there,
I would like to display the last X number of news items as a sub node of the main menu. I am using a MenuProvider to accomplish that. Adding the items is no problem, but I wonder what the best way to get the news items is. I found the NewsItem.GetAllNewsValidAndActiveAndNotArchive() method which seems to be exactly what I need. However, I think it could potentially return a large number of items, which seems overkill.
Using Reflector I saw the implementation of this method is quite straightforward. I could copy the implementation and modify it like this:
var allNewsValidAndActiveAndNotArchive =
DbHandler.ExecuteList<NewsItemCollection, NewsItem>(string.Format("SELECT TOP
3 * FROM [News] WHERE ([NewsActive] = {0}) AND (NewsArchive <> {1})
AND ({2} > [NewsActiveFrom]) AND ({2} <= [NewsActiveTo]) ORDER BY
[NewsDate] DESC", DbHandler.SqlBool(true), DbHandler.SqlBool(true),
DbHandler.SqlDate(DateTime.Now)), "Dynamic.mdb");
Works perfectly, but might break in the future when the logic to determine an active news item changes.
Are there alternatives? If not, is an overload of GetAllNewsValidAndActiveAndNotArchive with an argument for the MAX count a possible enhancement request?
Thanks,
Imar
Developer forum
Getting the latest few news items
Replies
You must be logged in to post in the forum