Associating Items With Taxa

Associating a content item with a Taxon

The content organization in Sitefinity is entirely based on Taxonomies. As shown in Flat Taxonomies and Hierarchical Taxonomiesarticles, the Tags and Hierarchical Categories are implemented as taxonomy. That said, when a content is tagged or categorized, a taxon is being associated with it. Here is how this association could be done via code:

//Taxonomies Namespaces
using Telerik.Sitefinity.Taxonomies;
using Telerik.Sitefinity.Taxonomies.Model;
//Generic Content namespaces
using Telerik.Sitefinity.Modules.GenericContent;
using Telerik.Sitefinity.GenericContent.Model;
..
..
var taxManager = TaxonomyManager.GetManager();
var taxonId = taxManager.GetTaxa<FlatTaxon>().Where(t => t.Name == "Book").Single().Id;
var contentManager = ContentManager.GetManager();
var allContent = contentManager.GetContent();
foreach (var content in allContent)
{
    content.Organizer.AddTaxa("Tags", taxonId);
}
contentManager.SaveChanges();

In this example, we are adding a tag named Book, to all content items. Note the content Organizer class - every content item type has it, in this case pages.

This approach can be used with all types of Content in Sitefinity, as well as pages. 

See Also

Other Resources

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK