How to get all news categories programatically.

Posted by Community Admin on 04-Aug-2018 07:17

How to get all news categories programatically.

All Replies

Posted by Community Admin on 02-Dec-2011 00:00

I am using sitefinity 4.3. I need a code to get all news categories. I cannot able to get this in forum section.

Posted by Community Admin on 02-Dec-2011 00:00

Can u pls suggest ASAP.

Posted by Community Admin on 02-Dec-2011 00:00

Any reply pls...

Posted by Community Admin on 02-Dec-2011 00:00

Hey man any reply...

Posted by Community Admin on 05-Dec-2011 00:00

Hey guys,

Can you reply for this..We are using your product which has to be supported properly. There are too many issue's guys.
How you are able to release like this??

Posted by Community Admin on 05-Dec-2011 00:00

Hi Sathiyaseelan,

As per your license agreement our support services are offered from Monday till Friday which excludes Saturday and Sunday. Also the guaranteed response time for your license is 72h which includes the forum type of conversation. More information about the support plans can be found here.

In order to achieve the desired scenario you need to get all categories and see which one of them is used in the news items. You can refer to our documentation and especially the section regarding the hierarchical taxonomies:

http://www.sitefinity.com/40/help/developers-guide/sitefinity-essentials-taxonomies-hierarchical-taxonomies-hierarchical-taxonomy-api.html

http://www.sitefinity.com/40/help/developers-guide/sitefinity-essentials-taxonomies-associating-items-with-taxa.html

You can also use the following code:

var dataItem = App.WorkWith().News().Get().Where(p => p.Title == Newsitemtitle).First();
var propDesc = OrganizerBase.GetProperty(dataItem.GetType(), "Category") as TaxonomyPropertyDescriptor;
if (propDesc != null)
    var taxonIds = propDesc.GetValue(dataItem) as IList<Guid>;
    var taxonomyManager = TaxonomyManager.GetManager();
    var taxa = new List<string>();
    foreach (var taxonId in taxonIds)
    
        taxa.Add(taxonomyManager.GetTaxon(taxonId).Title);
    


Regards,
Victor Velev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 06-Dec-2011 00:00

Hello,

I found it by digging. Your reply was not good enough still.
            /* List of all categories */
            Telerik.Sitefinity.Taxonomies.TaxonomyManager manager1 = Telerik.Sitefinity.Taxonomies.TaxonomyManager.GetManager();
            IList categoryList = manager1.GetTaxa<Telerik.Sitefinity.Taxonomies.Model.HierarchicalTaxon>()
                                    .Where(t => t.Taxonomy.Title == "Categories")
                                    .Select(t =>
                                        new Id = t.Id, Name = t.Title.ToString() )
                                    .OrderByDescending(t => t.Name)
                                    .ToList();

How to get the categories associated to a particular news by passing News ID..? Can I get at-least  an answer for this.

Thanks,

Posted by Community Admin on 06-Dec-2011 00:00

Sathiyaseelan,

This post will help you. I've tested the code and know it works.

Hope that helps!

This thread is closed