Excluding specific tags from tag lists that is being displayed
Hello,
On my blog listing page. I have 3 blocks for the 3 most recent articles.
On each of those blocks are displayed the tags from each article.
In each of those tags list there is a tag corresponding to the status of the article (New article, Editor's pick) and depending of this choice it is displaying a small label on the article itself.
However to avoid repeating the tags that are indicated in the labels, I would like to hide them.
So to do that I wrote the following code which is working like I want
<div class="tags">
{% set taglist = recentposts[0].tag_list %}
{% for tags in taglist %}
{% if !(tags == "Editor's_pick" || tags == "New_Article") %} {% set tags = tags|join(", ") %} {% set tags = tags|replace("_"," ") %}
{{ tags }}
{% endif %}
{% endfor %}
</div>
The only issue I have with this is that I would need to add a coma after each tag except if there is only one tag showing up and except on the last tag appearing.
How should I proceed, is there an easier solution ? (I though about using the |join filter but doesn't seem to work)
By the way I dont get why I can't save my code if I remove the {% set tags = tags|join(", ") %} so that's why I let it.
When I print the taglist variable it is showing all the different tags I added for this post when creating the post so for example [New_Article, Editor's pick, Lifestyle]