Answers.Body: <p>Something like this should work:</p>
  
  <pre><code>{% set tags = craft.tags.limit(null).relatedTo(craft.entries.limit(null)).order('title') %}
  
  {% for tag in tags %}
      &lt;a href="/tags/{{ tag.slug }}"&gt;{{ tag.title }} (craft.entries.relatedTo(tag).total())&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
  <p>Note that if you have a significant amount of tags, the above could be a costly affair, performance wise – <a href="https://craftcms.stackexchange.com/a/884/1098">consider alternative approaches</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-26T16:36:41.640Z
Answers.LastActivityDate: 2016-12-26T16:36:41.640Z
Answers.LastEditDate: 2017-04-13T12:51:00.200Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>I want to be able to display the number of entries that have a tag. Like:</p>
  
  <p>Fruit (9)
  Vegetables (4)</p>
  
  <p>I also want to avoid displaying any tags without any related entries.</p>
  
  <p>My code right now looks like this:</p>
  
  <pre><code>{% extends "_layout" %}
  {% set title = "Tags" %}
  {% block content %}
  {% for tag in craft.tags.order('title') %}
      &lt;li&gt;}&lt;a href="{{ siteUrl }}tags/{{ tag.title}}"&gt;{{ tag.title }}&lt;/a&gt;&lt;/li&gt;
  {% endfor %}
  {% endblock %}
  </code></pre>
  
Tags: <tags><relatedto><count>
Title: How to display number of entries for a tag and not display if no entries?
ThreadText: # How to display number of entries for a tag and not display if no entries?
  
  (Asked by: username_0 on 2016-12-25)
  
  I want to be able to display the number of entries that have a tag. Like:
  
  Fruit (9)
  Vegetables (4)
  
  I also want to avoid displaying any tags without any related entries.
  
  My code right now looks like this:
  
  ```
  {% extends "_layout" %}
  {% set title = "Tags" %}
  {% block content %}
  {% for tag in craft.tags.order('title') %}
      <li>}<a href="{{ siteUrl }}tags/{{ tag.title}}">{{ tag.title }}</a></li>
  {% endfor %}
  {% endblock %}
  
  ```
  
  **Tags:** tags, relatedto, count
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-12-26. Score: 4 | Accepted answer
  
  Something like this should work:
  
  ```
  {% set tags = craft.tags.limit(null).relatedTo(craft.entries.limit(null)).order('title') %}
  
  {% for tag in tags %}
      <a href="/tags/{{ tag.slug }}">{{ tag.title }} (craft.entries.relatedTo(tag).total())</a>
  {% endfor %}
  
  ```
  
  Note that if you have a significant amount of tags, the above could be a costly affair, performance wise – [consider alternative approaches](https://craftcms.stackexchange.com/a/884/1098).
  
  
  ---
  
  