Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Count of Taxonomy

Started by Muut Archive 10 years ago · 1 replies · 432 views
10 years ago

I would like to get a total count of instances of a specific taxonomy. Below is my current code.

TWIG
{% set taxlist = taxonomylist.get() %} {% if taxlist %}
<div class="tags">
    {% for tax,value in taxlist[taxonomy] %} {% set active = uri.param(taxonomy) == tax ? 'active' : '' %}
    <li><a class="{{ active }}" href="{{ base_url_absolute }}/filter/{{ taxonomy }},{{ config.system.param_sep }},{{ tax }}">{{ tax|capitalize }} {{taxlist|count}}</a></li> {% endfor %}
</div> {% endif %} 

I see that

TWIG
{{ dump(taxonomylist)}}

Does output:

JS

  "tag" => array:6 [
      "manager" => 3
      "testing" => 1
      "technical" => 1
      "hardening standard" => 1
      "data classification" => 1
      "techical" => 1
---
10 years ago

I was able to figure this out. For the newbies out these who might want to reuse this code:

TWIG

{% set taxlist = taxonomylist.get() %} {% if taxlist %}
<div class="tags">
    {% for tax, value in taxlist[taxonomy]|ksort %} {% set active = uri.param(taxonomy) == tax ? 'active' : '' %}
    <li><a class="{{ active }}" href="{{ base_url_absolute }}/filter/{{ taxonomy }},{{ config.system.param_sep }},{{ tax }}">{{ tax|capitalize }} ({{value}})</a></li> {% endfor %}
</div> {% endif %},{{ dump(taxlist)}}

I added the ....({{value}}).... portion of the code to add the count for a specific taxonomy.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1362 9 years ago
Archive · by Muut Archive, 9 years ago
2 939 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2959 9 years ago
Archive · by Muut Archive, 9 years ago
3 1124 9 years ago