More in this section

Forums / General Discussions / Category for the current NewsItem

Category for the current NewsItem

3 posts, 0 answered
  1. Vladimir
    Vladimir avatar
    4 posts
    Registered:
    14 Nov 2008
    19 Oct 2010
    Link to this post
    Hi,
    I've created a Page "NewsMain" which contains the built-in news content widget. There are a couple of category classifications (Taxonomy) for the News Items. In my own, custom widget, how can I get the category associated with the current NewsItem list or the category for the current news item?

     

    For example - this is the root news page:
    http://sf4website/NewsMain/ - it contains my custom widget and I want to get the categories associated with the newsitems here.
    And this is the news details page -
    http://sf4website/newsmain/2010/10/15/FirstNewsPageTest/ - I want to get the category here also.
    Is there any method which I can use to get the current categories? I've searched the documentation and the forums, but I coudn't find any.
  2. Vladimir
    Vladimir avatar
    4 posts
    Registered:
    14 Nov 2008
    22 Oct 2010
    Link to this post
    Hi,
    I've managed to find the category for the currently loaded news item. This is the code which I use to get the first category for a given News item: 
    01.private HierarchicalTaxon GetFirstCategory(TaxonomyManager taxonManager)
    02.       {
    03.           // get the first category for the current item
    04.           HierarchicalTaxon firstCategory = null;
    05.           NewsManager cntManager = NewsManager.GetManager();
    06.           string urlParameterString = this.GetUrlParameterString();
    07.           string redirectUrl;
    08.           if (!string.IsNullOrEmpty(urlParameterString))
    09.           {
    10.               NewsItem item = cntManager.GetItemFromUrl<NewsItem>(urlParameterString, out redirectUrl);
    11.               if (item != null)
    12.               {
    13.                   IList<Guid> categoryIds = (IList<Guid>)item.GetValue("Category");
    14.                   Guid firstCategoryId = categoryIds.FirstOrDefault();
    15.                   if (Guid.Empty != firstCategoryId)
    16.                   {
    17.                       firstCategory = taxonManager.GetTaxon<HierarchicalTaxon>(firstCategoryId);
    18.                   }
    19.               }
    20.           }
    21.             
    22.           return firstCategory;
    23.       }

     
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    22 Oct 2010
    Link to this post
    Hi Vladimir,

    You might also find these posts useful

    Currently the only way to get a category for an item is through the DataExtensions methods.
    Best wishes,
    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
3 posts, 0 answered