How to display number of entries for a tag and not display if no entries? 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') %}
    &lt;li&gt;}&lt;a href="{{ siteUrl }}tags/{{ tag.title}}"&gt;{{ tag.title }}&lt;/a&gt;&lt;/li&gt;
{% endfor %}
{% endblock %}
Something like this should work:

{% 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 %}


Note that if you have a significant amount of tags, the above could be a costly affair, performance wise – consider alternative approaches.