Taxonomies are an important tool for structuring, organizing and categorizing content. Taxonomies allow administrators to create and organize tags in a hierarchical manner. Content editors benefit from these structures by tagging pages, emails, headless and reusable items, improving navigation and connections among related information. For developers, this page explains how to leverage tags to fetch and display related content.
Within the Xperience by Kentico environment, users can work with taxonomies and tags:
To start using taxonomies in your project:
Before you enable content editors to assign tags to content, you need to create taxonomies and tags.
To create a new taxonomy:
The taxonomy is now created and you can add tags.
Tip: When you edit an already created taxonomy, you can also localize the Taxonomy name field.
To create new tags:
You can enable content editors to add tags to items.
See Add option to tag content for more information.
You can limit the retrieval query to only retrieve content items with the specified tags using the WhereContainsTags content item query parametrization method.
See Retrieve content items for more information.
You can enable content editors to select tags in builder component and administration UI component properties. Content editors can select tags in form component properties and these tags can be used to retrieve specific content with the selected tags.
Add the TagSelectorComponent editing component to your component's properties. See Tag selector and Editing components for more information.
If you want to display information about a particular taxonomy (e.g., a component on the live site that allows you to filter articles by their tags) you can use the RetrieveTaxonomy method of the ITaxonomyRetriever interface.
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CMS.ContentEngine;
public class CustomComponent(ITaxonomyRetriever taxonomyRetriever)
{
public async Task RetrieveTaxonomyData()
{
// Retrieves the general TaxonomyData object for a selected taxonomy
TaxonomyData taxonomyData = await taxonomyRetriever.RetrieveTaxonomy("ArticleCategory", "en");
// Retrieves data about the taxonomy from the TaxonomyData object
var taxonomy = taxonomyData.Taxonomy;
string taxonomyDisplayName = taxonomy.Title;
string taxonomyCodeName = taxonomy.Name;
// Retrieves the collection of all tags within the taxonomy
IEnumerable<Tag> tags = taxonomyData.Tags;
// Retrieves data about a tag within the taxonomy
Tag someTag = tags.FirstOrDefault();
string tagDisplayName = someTag.Title;
string tagCodeName = someTag.Name;
// ...
}
}To create taxonomies programmatically, refer to the API examples.