Category for the current NewsItem
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:
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. Hi Vladimir,
You might also find these posts useful