Item Counts For Categories

  • I want to create item counts for categories as described here Category count?


    Stephen Meehan - did you solve this?


    I can use <perch:content id="perch_item_count" type="hidden"> in a template on the region page but I need to display the counts on my category list on a separate page.


    I think this should be possible using each as follows:


    Code
    1. perch_categories([
    2. //category filtering here
    3. 'each' => function($item) {
    4. // get the count here
    5. return $item;
    6. },
    7. ]);

    Has anyone else done this??

  • Yes, try this:


  • Great stuff, that's working, thank you.


    I will add a filter on the categories so that I get some categories and not all:


    I may also template the output although perhaps not really needed.

    Many thanks again.

  • Here's my final code. It has some additional category and item filtering in it.


    I am using replace in the Perch template to get the correct URL so that's why I have used perch_template.