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??

  • Sorry, I meant counting the items that belong to a category. Your example would count the categories I think.


    Perhaps the Stephen Meehan example is misleading. I have a multiple item region with categories (countries). I want to display the categories (countries) with the number of items in each category.

  • 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.