1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Content Classification & Taxonomies

Content Classification & Taxonomies

2 posts, 1 answered
  1. Jeff Vail
    Jeff Vail avatar
    14 posts
    Registered:
    06 Dec 2003
    18 Aug 2010
    Link to this post
    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.  ;)

    Thanks,
    Jeff
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    19 Aug 2010
    Link to this post
    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";
                      break;
                  case TaxonomyType.Hierarchical:
                      taxonomy = taxonomyManager.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name == taxonomyName).SingleOrDefault();
                      iconCss = "sfHierarchicalTaxonIcn";
                      break;
                  case TaxonomyType.Facet:
                      taxonomy = taxonomyManager.GetTaxonomies<FacetTaxonomy>().Where(t => t.Name == taxonomyName).SingleOrDefault();
                      break;
                  case TaxonomyType.Network:
                      taxonomy = taxonomyManager.GetTaxonomies<NetworkTaxonomy>().Where(t => t.Name == taxonomyName).SingleOrDefault();
                      break;
              }
     
              // 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>();
                          break;
                      case TaxonomyType.Hierarchical:
                          taxonomy = taxonomyManager.CreateTaxonomy<HierarchicalTaxonomy>();
                          break;
                      case TaxonomyType.Facet:
                          taxonomy = taxonomyManager.CreateTaxonomy<FacetTaxonomy>();
                          break;
                      case TaxonomyType.Network:
                          taxonomy = taxonomyManager.CreateTaxonomy<NetworkTaxonomy>();
                          break;
                  }
     
                  taxonomy.Name = taxonomyName;
                  taxonomy.Title = taxonomyTitle;
                  taxonomyManager.SaveChanges();
     
                  // 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;
                      type.Fields.Add(field);
                  }
              }
     
              metaMan.SaveChanges(true);           
          }

    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
    Answered
2 posts, 1 answered