Using Categories control to limit shown categories
Hi
I have a categories control on a page. By default it shows all categories. I would like to limit it to showing only the sub-categories contained in a specific category. How can I do this?
thanks,
Dan
Hello Dan,
Thank you for using our services.
Here's how to create a sub-category category widget:
1. First we add a class file to our Sitefinity project and name it CustomTaxonomyControl. Our class inherits from TaxonomyControl. The TaxonomyControl has several modes in which it renders taxonomies - HorizontalList, VerticalList and Cloud. Each one of the options is represented by a Repeater on the front-end. We override InitializeControls method of TaxonomyControl and subscribe to the TaxaRepeater ItemDataBound event. TaxaRepeater is the repeater, which renders our taxonomies. Then we can the base implementation of InitializeControls:
protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container) this.TaxaRepeater.ItemDataBound -= base.TaxaRepeater_ItemDataBound; this.TaxaRepeater.ItemDataBound += TaxaRepeater_ItemDataBound123; base.InitializeControls(container); protected internal virtual void TaxaRepeater_ItemDataBound123(object sender, RepeaterItemEventArgs e) base.TaxaRepeater_ItemDataBound(sender, e); if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) var taxonData = e.Item.DataItem as TaxonData; var link = e.Item.FindControl("link") as HyperLink; if (link != null) if (ParentCategory!=null && !taxonData.Url.Contains(ParentCategory.Trim().ToLower() + "/")) e.Item.Visible = false; Hi, I'm trying to put this to work.
I got the control registered and I can add it to a page.
When I add the parent ParentCategory all the categories disappear. No errors, in the code only the ul gets printed.
I'm sure the id of the ParentCategory is correct, what am I missing?
Hello Filippo,
Could you please provide your control in order to inspect the code or open a support ticket on that matter.
In addition you can take a look on the Taxonomies API documentation.
Regards,
Svetoslav Manchev
Telerik