<p>You don't have a setting in Craft to make Tags have their own pages automatically. So what you have to do instead, is to set up a <a href="https://craftcms.com/docs/routing#dynamic-routes" rel="nofollow">dynamic route</a> in Settings → Routes. Create a new route which routes these URIs: blog/tags/[slug] (drag the slug token into the URI field) to a template blog/_tags.html.</p>

<p>In your blog/_tags.html template you will now have a slug variable available, but you still need to query for the tag model / entry models.</p>

<pre><code>{% set tag = craft.tags.slug(slug).first() %}
{% if not tag %}{% exit 404 %}{% endif %}

{% set entries = craft.entries.section('blog').relatedTo(tag).limit(null) %}

&lt;h2&gt;{{ tag.title }}&lt;/h2&gt;

{% for entry in entries %}
{% endfor %}
</code></pre>

<p>I'd also modify the tag listing to only show tags that are actually related to an entry, and use the tags' (undocumented) slug property for SEO purposes:</p>

<pre><code>{% set entries = craft.entries.section('blog').limit(null) %}
{% set tags = craft.tags.relatedTo(entries).limit(null) %}

{% for tag in tags %}
    &lt;a href="{{ url('blog/tags/'~tag.slug) }}"&gt;{{ tag.title }}&lt;/a&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-12-05T10:13:06.473Z
2015-12-05T10:13:06.473Z
carlcs
<p>I have a blog, and in the sidebar I have listed all tags in use. I would like to link each tag - when you click it I want to link to a page that lists all the blog entries which have that tag applied to them. Cant find this in the docs.. would someone mind helping? Here is my code so far: </p>

<pre><code>&lt;div class="tagblock"&gt;
    {% set entries = craft.entries.section('blog').limit(null) %}
         {% for tag in craft.tags %}
           &lt;div class="tag"&gt;&lt;a href="{{ url('blog-page/'~tag.id) }}"&gt;{{ tag.title }}&lt;/a&gt;&lt;/div&gt;
    {% endfor %}
&lt;/div&gt;
</code></pre>

<p>MY RESULTS: This code is linking to for example mysite.com/blog-page/88 - and giving me a page not found. I have a template blog-page and the path is correct as the page loads if you remove the tag-id off the end. </p>

<p>Thanks</p>

<entries><tags>
Listing All tags - and linking them to list of entries with that tag
# Listing All tags - and linking them to list of entries with that tag

(Asked by: username_0 on 2015-12-05)

I have a blog, and in the sidebar I have listed all tags in use. I would like to link each tag - when you click it I want to link to a page that lists all the blog entries which have that tag applied to them. Cant find this in the docs.. would someone mind helping? Here is my code so far: 

    {% set entries = craft.entries.section('blog').limit(null) %}
         {% for tag in craft.tags %}
           {{ tag.title }}
    {% endfor %}


MY RESULTS: This code is linking to for example mysite.com/blog-page/88 - and giving me a page not found. I have a template blog-page and the path is correct as the page loads if you remove the tag-id off the end. 
Thanks

**Tags:** entries, tags

---

## 1 answers

### Answer by username_1 on 2015-12-05. Score: 4

You don't have a setting in Craft to make Tags have their own pages automatically. So what you have to do instead, is to set up a dynamic route in Settings → Routes. Create a new route which routes these URIs: blog/tags/[slug] (drag the slug token into the URI field) to a template blog/_tags.html.
In your blog/_tags.html template you will now have a slug variable available, but you still need to query for the tag model / entry models.
{% set tag = craft.tags.slug(slug).first() %}
{% if not tag %}{% exit 404 %}{% endif %}

{% set entries = craft.entries.section('blog').relatedTo(tag).limit(null) %}

{{ tag.title }}

{% for entry in entries %}
{% endfor %}

I'd also modify the tag listing to only show tags that are actually related to an entry, and use the tags' (undocumented) slug property for SEO purposes:
{% set entries = craft.entries.section('blog').limit(null) %}
{% set tags = craft.tags.relatedTo(entries).limit(null) %}

{% for tag in tags %}
    {{ tag.title }}
{% endfor %}


---

