Hi Nathalia,
Let me elaborate a little bit on the default taxonomies functionality in Sitefinity.
By default you have two types of classifications -
Hierarchical Taxonomy and
Flat Taxonomy. Flat taxonomies(as the name suggests) have a flat structure (e.g. they do not support parent-child hierarchy). An example of the Flat taxonomies in Sitefinity is Tags - you have the base Flat Taxonomy Tags, and all tags you've assigned to your content are stored under Tags.
Categories, on the other side are an example of Hierarchical taxonomy - you can have a Parent Category, and then Child category, which allows you to structure your content hierarchically. Departments is another example of Hierarchical taxonomies, which is specific for content items of type Product (since it makes more sense to group your products in different departments).
You can create your own classifications as well, besides the default ones, and assign your content items to then, what's important to know is that you need to specify the correct type when working with classifications through code.
Let's take for example News. If you want to get all the categories that are assigned to a News item, you'll need to get the value of the metafiled Category, and this value will be a list of Category IDs. In the same line of reasoning, you can get all the Departments, to which a product belongs by getting the value of the metafield "Departments". Let's take the code sample we provided in our previous reply and explain it in more details, I believe this might be useful:
//First get the manager which operates with Taxonomies
TaxonomyManager manager = TaxonomyManager.GetManager();
//Get the manager corresponding to the Content type you'll be operating with
CatalogManagerpManager = CatalogManager.GetManager();
//Get the ID of a singe instance (HierarchicalTaxon) of type Hierarchicaltaxonomy
//(This can be Categories, Departments, or any custom HierarchicalTaxonomy)
var myCategoryId = manager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name == "TT").Single().Id;
//Get a list of content items of the desired Content type
var productList = pManager.GetProducts().ToList();
//For each of the content items in the above constructed list
foreach (var product in productList)
{
//Get all the IDs of the HierarchicalTaxons in the HierarchicalTaxonomy "Departments"
// which is stored in the "Department metafield of this content item"
var catlist = product.GetValue<TrackedList<Guid>>("Department");
//modify the list as per your requirements
catlist.Add(myCategoryId);
//assign the modified list to the "Department metafield of this content item
//this is equivalent to adding a new Department to a product through the UI
product.SetValue("Department", catlist);
}
//Commit the changes
pManager.SaveChanges();
in that line of reasoning the same sample can be easily implemented for News items like this:
I believe you might find the
Taxonomies section from our Documentation very useful in terms of presenting the theoretical base behind classifications in Sitefinity. Please do not hesitate to let us know if you need some further information.
Regards,
Boyan Barnev
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