News list widget template - how to get category hyperlink

Posted by Community Admin on 04-Aug-2018 21:55

News list widget template - how to get category hyperlink

All Replies

Posted by Community Admin on 09-May-2013 00:00

I'm displaying categories field in my custom widget template for News List.  How do I make the categories hyperlinks so they can filter the news list according to the clicked category?  This functionality was built-in before SF 4, I believe.

Here's my field for displaying categories in widget template?

<sitefinity:HierarchicalTaxonField ID="HierarchicalFieldControl" runat="server" TaxonomyId="E5CD6D69-1543-427b-AD62-688A99F5E7D4" DisplayMode="Read" WebServiceUrl="~/Sitefinity/Services/Taxonomies/HierarchicalTaxon.svc" Expanded="false" TaxonomyMetafieldName="Category" ExpandText="ClickToAddCategories" BindOnServer="true" />

p.s.  I know I can filter by category by dropping a Categories widget.  I'm already doing that.  But it makes sense that when someone is viewing an article and seeing its categories, he/she can click on it right there and view all other news stories of same category.

Posted by Community Admin on 14-May-2013 00:00

Hi Marko,

Thank you for contacting Telerik Support.

As you properly pointed out , indeed this functionality has not been implemented yet in the new Sitefinity  architecture. As such it is currently logged as a a feature request in our system, you can track its status and vote for its popularity in PITS here.

In the meantime  you can achieve this with an external widget template which will have a control to render the click-able output (e.g. Literal) and in its code behind you can implement a method that will construct the correct filtering URL parameters, here's a similar example that might help you get started:

Copy Code
public string RenderHierarchicalTaxaAsLink(NewsItem newsitem, string taxonomyFieldName)
           var catList = "";
           var categories = newsitem.GetValue<TrackedList<Guid>>(taxonomyFieldName);
           if (categories != null && categories.Count() > 0)
               catList = "Categories:</br> ";
               var currentUrl = HttpContext.Current.Request.Url.ToString();
               currentUrl = currentUrl.TrimEnd('/');
               var taxManager = TaxonomyManager.GetManager();
               foreach (var cat in categories)
                   var t = taxManager.GetTaxon<HierarchicalTaxon>(cat);
                   var url = string.Format("0/-in-1/2/3",currentUrl, t.Taxonomy.TaxonName, t.Taxonomy.Name, t.Name);
                   var link = string.Format( "<a href='0'>1</a><br/>", url, t.Name).ToString();
                   catList = catList + link;

Please do not hesitate if there's anything else I can assist you with, or if you have any further question on the above sample, I'll be glad to help.

Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 14-May-2013 00:00

Thanks.  I will wait for this functionality, rather than implement my custom external template at this point.

This thread is closed