Total article count for each home page category. | Community
Skip to main content

Total article count for each home page category.

  • February 22, 2022
  • 5 replies
  • 0 views

Hi all, 

I'm trying to figure out how to have my home page categories display the total number of articles.

The example below is what I've previously done on WordPress (title, total, articles listed/ sections listed):


I know the category page can show the article count per section, but I'd like the total count for every article in a category:
Any tips would be great, I'm mostly getting error messages so far trying different helpers.

5 replies

  • February 22, 2022
Hi Connor!
 
I think the best way to do this would be to use our [List Articles API](https://developer.zendesk.com/api-reference/help_center/help-center-api/articles/#list-articles) to query each article for their section id first, then use the section id to track which category id it belongs via the [Show Section API]. It's a little bit of traversing through 2 different endpoints but you should be able to track how many articles are in each Category that way.
 
You actually could create an object to first record the total of articles per sections. 
{
 section_id: total # articles in section
}
 
Then create another object where the category_id is each key. You'll only need to traverse through each section id in the first object then use it to hit the Show Section API, based on the category_id increment the value for the given category_id or if it doesn't exist yet in your object create it and +1 for the value. It will also be a good way to keep that data dynamic for when you add or remove articles. 
 
Hope this helps!
 
Best, 
 
Erica Girges - Dev Support

Shawn32
  • April 1, 2022

Hi Erica

Would you be able to provide a working example? I want to achieve the same thing but unfortunately this is a bit of a technical hurdle.


  • April 8, 2022
Hi Shawn,
 
I can definitely put together an example of a script to query/calculate for this data. Since we're about to head into the weekend, I can guarantee that I can have it for you by Monday. 
 
Best,
 
Erica 
 
 

Shawn32
  • April 11, 2022

Much appreciated, thank you Erica.


  • April 12, 2022
Hi Shawn,
 
Thanks for your patience. Here is the link to the repo I created. I just threw the script into a Zendesk App using ZCLI for testing purposes but you should be able to implement the same logic without the app. 
 
https://github.com/ericagirges/calculate-articles-per-category/blob/main/assets/main.js
 
Just a heads up, I put this together to demonstrate the ability to gather this data by traversing through Article related endpoints. It won't be a maintained script and without knowing your codebase I can't guarantee it will work for your use case. Hopefully at the least it can get you in the right direction.
 
Hope this helps!
 
Erica