Category for the current NewsItem

Posted by Community Admin on 03-Aug-2018 15:55

Category for the current NewsItem

All Replies

Posted by Community Admin on 19-Oct-2010 00:00

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.

Posted by Community Admin on 22-Oct-2010 00:00

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.       

 

Posted by Community Admin on 22-Oct-2010 00:00

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

This thread is closed