Blog Categories only in dropdown list
I've bee able to build a custom dropdown list control based on this thread:
http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/categorytree.aspx
However, I want to take it one step further and ONLY show the categories that are used in blog posts.
How could I expand upon the post above to accomplish this?
Thank you.
Hi Amir,
Can you attach the control that you have build so we can have a look at it and see whats the proper way to implement the required code?
Kind regards,
Victor Velev
the Telerik team
Thanks Victor,
Here is the current code:
protected void Page_Load(object sender, EventArgs e) var tm = TaxonomyManager.GetManager(); var tax = tm.GetTaxonomy(TaxonomyManager.CategoriesTaxonomyId); var taxa = tax.Taxa; categorylist.Items.Add(new ListItem("Categories", "0")); foreach (HierarchicalTaxon taxon in taxa) string url = ""; var evaluator = new TaxonomyEvaluator(); var taxonBuildOptions = TaxonBuildOptions.None; if (tax is HierarchicalTaxonomy) taxonBuildOptions = TaxonBuildOptions.Hierarchical; else if (tax is FlatTaxonomy) taxonBuildOptions = TaxonBuildOptions.Flat; string evaluatedResult = "/blog" + evaluator.BuildUrl(tax.Name +"/", taxon.UrlName, "Category", taxonBuildOptions, UrlEvaluationMode.UrlPath, null); var li = new ListItem(taxon.Title, evaluatedResult); categorylist.Items.Add(li); Hello Amir,
Thank you for providing the code. We will need some more time to explore the code and provide you with a solution.
Best wishes,
Victor Velev
the Telerik team
Hi Amir,
We have prepared a sample code for you. Feel free to modify it so it suits your needs:
var catList = new List<ITaxon>(); var blogPosts = App.WorkWith().BlogPosts().Get().ToList(); if (blogPosts != null) var manager = TaxonomyManager.GetManager(); foreach (var blog in blogPosts) var blogsCats = blog.GetValue<TrackedList<Guid>>("Category"); if (blogsCats != null) foreach (var cat in blogsCats) var category = manager.GetTaxon(cat); if (category != null && !catList.Contains(category)) catList.Add(category); foreach (var c in catList) string url = ""; var evaluator = new TaxonomyEvaluator(); var taxonBuildOptions = TaxonBuildOptions.None; if (c is HierarchicalTaxonomy) taxonBuildOptions = TaxonBuildOptions.Hierarchical; else if (c is FlatTaxonomy) taxonBuildOptions = TaxonBuildOptions.Flat; string evaluatedResult = "/blog" + evaluator.BuildUrl(c.Name + "/", c.UrlName, "Category", taxonBuildOptions, UrlEvaluationMode.UrlPath, null); categorylist.Items.Add(c.Title);