I’m trying to add tags to my blog posts.
I’ve created a tags group with the handle ‘default’.
In Setting/Fields I’ve got a field called bodyElements which is setup as a matrix, and within bodyElements I’ve added to the Configuration a block type called Tags with a handle of ‘tags’, and then within that there’s a field called Tags with a handle of ‘blogTags’ and this is set as the Field Type of “Tags” and the Source is set as “Tags”.
Now when I go to a blog post, I can type in my content and click the button to add a Tag. I can then type in a tag and it attaches to that particular entry.
The issue I’m having is that when I view the blog posts on the front end, the tags are showing up on every single post, even though they don’t have those tags attached to them.
On https://craftcms.com/support/active-tags it says to insert the following code to display only the tags that are in use
{% set entries = craft.entries.section('news').limit(null) %}
<ul>
{% for tag in craft.tags.relatedTo(entries) %}
<li>{{ tag.title }}</li>
{% endfor %}
</ul>
but that doesn’t display the tags at all.
My blog section has a handle of ‘blog’, so in the above code I tried replacing ‘news’ with ‘blog’ and still no tags appear.
The only way I can get tags to appear on my posts is by using the following code:
{% for tag in craft.tags.group(‘default’) %}
<li><a href="{{ url('blog/tags/'~tag.id) }}">{{ tag.title }}</a></li>
{% endfor %}
but the above code caused the tags to appear on every single blog post, even if they’re not tagged with anything.
How do I get the tags to only appear on the posts the tags are attached to?
Thanks.