Recently I was tasked to develop a list of categories displaying how many items are in each category. If displaying just the categories was a walk in park using the Category List web part, listing certain parent categories with the number of items under each category was no easy task. I did my share of online research and aside from bits and pieces apparently nobody actually had to develop this, or at least share their experience.
So, here I am, sharing the steps I had to go through to accomplish this task.
First, make sure you have your categories in order. So, head over to Categories application under Configuration section of your administration dashboard and create, if necessary, some global categories and assigned them some pages.
For the purpose of this post, I will use this mockup Categories:
Create a new page or go to a page you want to use to display the category list. Add a “Repeater with custom query:” web part to the page. For the Query name hit the New button to create a new query. Add the following code and Save & Close.
SELECT CategoryID, CategoryName, CategoryDisplayName, CategoryCount FROM CMS_Category WHERE (##WHERE##) ORDER BY CategoryDisplayName ASC
For the WHERE condition: add the following: CategoryParentID=3
Change the number 3 with your Category ID you want to display.
Next, move down to Transformation name: and click the New button to create a new transformation. Add the following code and Save & Close.
<li><%# Eval("CategoryID") %> - <%# Eval("CategoryDisplayName") %> (<%# Eval("CategoryCount") %>)</li>
And this is the final result. Note that I left the CategoryID to be displayed in purpose so it will be easier for you to see your category IDs. Feel free to remove it from the transformation.