How to query all news items by publication date? (And limit queries..)
I know this is likely a very basic question, but I'm a designer-turned-developer-by-necessity who's inherited a Sitefinity site to modify, and I'm completely new to Sitefinity, ASP.net, and C#. I've spent the last half-hour trying to figure this out...
In Sitefinity's documentation for querying all news items, it doesn't mention how to sort by publication date. I've back-published several news items, so I don't want it displayed by last modified or last created. I've tried looking into Administration > Settings > Advanced > News > NewsBackend/NewsFrontend > Views > NewsBackendList/NewsFrontendList and it doesn't seem to be there. I've also tried doing a custom sort in the News content view, and nothing changes.
The code in question uses the Native API in the code-behind file, and I'd like a way to sort by publication date, and paginate the results to show only 5 at a time:
01.
public
void
BindNews()
02.
03.
NewsCtrl.DataSource =
04.
NewsManager.GetManager()
05.
.GetNewsItems()
06.
.Where(p => p.Status == ContentLifecycleStatus.Live && p.Visible)
07.
.ToList();
08.
NewsCtrl.DataBind();
09.
This is how the code is called in the widget:
1.
<ItemTemplate>
2.
<li><span
class
=
"date"
><%# DataBinder.Eval(Container.DataItem,
"PublicationDate"
,
"0:D"
) %></span><br />
3.
<a href=
'/news-details<%# DataBinder.Eval(Container.DataItem, "ItemDefaultUrl") %>'
title=
'<%# DataBinder.Eval(Container.DataItem, "Title") %>'
>
4.
<%# DataBinder.Eval(Container.DataItem,
"Title"
) %></a><br />
5.
<p><%# DataBinder.Eval(Container.DataItem,
"Summary"
) %> <a href=
'/news-details<%# DataBinder.Eval(Container.DataItem, "ItemDefaultUrl") %>'
title=
'<%# DataBinder.Eval(Container.DataItem, "Title") %>'
>(Read more...)</a></p>
6.
</a>
7.
</li>
8.
</ItemTemplate>
Thanks for any help!
Hi Anita,
Can you please tell me whether you are using the out of the box News widget you are implementing custom solution? I am asking this question, because the desired filtration can be made using the default widget. You can find more detailed information how to do this from the following documentation article:
Filter expressions for content items
You have to enter this filter expression in the Advanced section of widget designer.
Regards,
Kaloyan
Telerik
Hi Kaloyan,
It's actually a custom solution that our developers implemented. They've called the news items in a custom widget, to put into a page.
I've had an ASP.NET developer come and look at the code, and we couldn't integrate his fix. I think the issue may be that I cannot build out the project in Visual Studio as a Sitefinity web app because of difficulties installing the database locally, as well as connecting the database to use Thunder. I'm modifying one file at a time, then uploading it to the Sitefinity project via File Manager. This means that the code-behind files are not integrated. I've found that I can modify the layout/HTML of existing widgets and master pages, but I cannot make new ones or add new content areas, and that's because I can't build the app out before uploading the files.
Is that an accurate assessment?
Thanks!
Hello Anita,
You can check the following forum thread. I think that it might help you to achieve your desired scenario.
Module Builder: sorting list items?
Regards,
Kaloyan
Telerik