Try Now
More in this section

Forums / Developing with Sitefinity / NewsManager GetContent - filter by category? Sorting expression of GetContent

NewsManager GetContent - filter by category? Sorting expression of GetContent

2 posts, 0 answered
  1. Andrew Maddison
    Andrew Maddison avatar
    3 posts
    06 Apr 2010
    11 Nov 2010
    Link to this post
    Hi There,

    We've built a simple user control to display the most recent news item, but were wondering if it's possible to filter the news items by category? Specifically, is there a way by changing the sorting expression passed in to the GetContent method?

    Here's our current code, you can see we're already ordering by Publication_Date to get the latest item, but I'm unsure of the syntax to use to filter by category.

    public partial class SitefinityNewsDefaultItem : System.Web.UI.UserControl
            public string NewsFeedName { get; set; }
            protected void Page_Load(object sender, EventArgs e)
                NewsManager newsManager = new NewsManager(String.IsNullOrEmpty(NewsFeedName) ? "News" : NewsFeedName);
                IContent latestNewsItem = newsManager.Content.GetContent("Publication_Date DESC")[0] as IContent;
                if (latestNewsItem != null)
                    NewsView newNewsItemControl = new NewsView();
                    newNewsItemControl.SelectedItemId = latestNewsItem.ID;

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    11 Nov 2010
    Link to this post
    Hi Andrew,

    GetContent method has about 21 overloads which you can use. Take a look at GetContent(int from, int max, string sortExp, params IMetaSearchInfo[] filter) - Get filtered subset of content with specified starting position and maximum number, ordered by sorting expression

    Category is a metakey so you can pass it to IMetaSearchInfo filter.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered