Content Classification & Taxonomies

Posted by Community Admin on 03-Aug-2018 20:38

Content Classification & Taxonomies

All Replies

Posted by Community Admin on 18-Aug-2010 00:00

Is there any documentation yet on classification that goes beyond Tags & Categories?  I am looking to design my own hierarchical taxonomy and apply that to content.  Will Generic Content and GC-based modules automatically be able to utilize the custom classifications built?  For example, I would like to develop a classified ad module that uses a three-level hierarchical classification (i.e. Transportation -> Cars -> Sports Cars).  The module will be GC-based.  Pretty easy to do?  I'm hoping to see some examples of more complex taxonomies, too.  I know, you're all hard at work on this, and I can patiently wait if it's not ready yet.  ;)


Posted by Community Admin on 19-Aug-2010 00:00

Hi Jeff Vail,

You can create such taxonomy - Transportation -> Cars -> Sports Cars throught the UI.
Anyway there is a sample code that illustrates how to create new Taxonomy and add it the to UI.

public static void TryCreateNewTaxonomy(string taxonomyTitle, string taxonomyName, TaxonomyType type, params Type[] contentTypes)
          if (string.IsNullOrEmpty(taxonomyTitle))
              throw new ArgumentNullException("taxonomyTitle");
          if (string.IsNullOrEmpty(taxonomyName))
              throw new ArgumentNullException("taxonomyName");
          var taxonomyManager = TaxonomyManager.GetManager();
          // first check if the taxonomy of specified type and name already exists.
          ITaxonomy taxonomy = null;
          var iconCss = string.Empty;
          switch (type)
              case TaxonomyType.Flat:
                  taxonomy = taxonomyManager.GetTaxonomies<FlatTaxonomy>().Where(t => t.Name == taxonomyName).SingleOrDefault();
                  iconCss = "sfFlatTaxonIcn";
              case TaxonomyType.Hierarchical:
                  taxonomy = taxonomyManager.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name == taxonomyName).SingleOrDefault();
                  iconCss = "sfHierarchicalTaxonIcn";
              case TaxonomyType.Facet:
                  taxonomy = taxonomyManager.GetTaxonomies<FacetTaxonomy>().Where(t => t.Name == taxonomyName).SingleOrDefault();
              case TaxonomyType.Network:
                  taxonomy = taxonomyManager.GetTaxonomies<NetworkTaxonomy>().Where(t => t.Name == taxonomyName).SingleOrDefault();
          // if the taxonomy of given name and specified type does not exist, we will create it here
          if (taxonomy == null)
              switch (type)
                  case TaxonomyType.Flat:
                      taxonomy = taxonomyManager.CreateTaxonomy<FlatTaxonomy>();
                  case TaxonomyType.Hierarchical:
                      taxonomy = taxonomyManager.CreateTaxonomy<HierarchicalTaxonomy>();
                  case TaxonomyType.Facet:
                      taxonomy = taxonomyManager.CreateTaxonomy<FacetTaxonomy>();
                  case TaxonomyType.Network:
                      taxonomy = taxonomyManager.CreateTaxonomy<NetworkTaxonomy>();
              taxonomy.Name = taxonomyName;
              taxonomy.Title = taxonomyTitle;
              // add dynamic fields to be used to store taxa from this new taxonomy
              Manager.AddTaxonomyFieldToModel(taxonomy, taxonomyManager.Provider.Name, contentTypes);
              // add the taxonomy control to the page editor toolbox
              TaxonomyControlManager.AddTaxonomyControlToToolbox((Taxonomy)taxonomy, iconCss, taxonomy.Name);
             // add user interface elements to the backend content forms
              Manager.AddUserInterfaceElementToBackendForm(type, taxonomy, contentTypes);
      private static void AddTaxonomyFieldToModel(ITaxonomy taxonomy, string taxonomyProvider, params Type[] contentTypes)
          MetaField field;
          var metaMan = MetadataManager.GetManager();
          foreach (var contentType in contentTypes)
              var type = metaMan.GetMetaType(contentType);
              if (type == null)
                  type = metaMan.CreateMetaType(contentType);
              var taxonomyName = taxonomy.Name;
              var result = metaMan.GetMetafields().SingleOrDefault(f => f.FieldName == taxonomyName);
              if (result == null)
                  field = metaMan.CreateMetafield(taxonomy.Name);
                  field.TaxonomyProvider = taxonomyProvider;
                  field.TaxonomyId = taxonomy.Id;
                  field.IsSingleTaxon = false;

There are still some issues that will stop you to achieve your goal with the BETA, but they will be sorted out for the RC.

Kind regards,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed