+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to query all news items by publication date? (And limit queries..)

How to query all news items by publication date? (And limit queries..)

4 posts, 0 answered
  1. Anita
    Anita avatar
    9 posts
    Registered:
    11 May 2015
    11 May 2015
    Link to this post

    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!

  2. Kaloyan
    Kaloyan avatar
    272 posts
    Registered:
    08 Dec 2016
    14 May 2015
    Link to this post
    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
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Anita
    Anita avatar
    9 posts
    Registered:
    11 May 2015
    14 May 2015 in reply to Kaloyan
    Link to this post

    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!

  4. Kaloyan
    Kaloyan avatar
    272 posts
    Registered:
    08 Dec 2016
    19 May 2015
    Link to this post
    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
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
4 posts, 0 answered