Tag Liquid

4:54a.m. *Mephisto-Fu — Nice Tags

I’m silly. I like my tags to read:

tag-one, tag-two and tag-three

Instead of:

tag-one, tag-two, tag-three

When I used WordPress, I used a plugin called Nice Categories to have an ‘and’ added and comma removed before the last tag. Thanks to Liquid, I can do the same without a plugin. In your default article template, it would be:

{% for tag in article.tags %}
{% if forloop.length == 1 %}
{{ tag | link_to_tag }}
{% elsif forloop.length == 2 %}
{% if forloop.last  %}
 and {{ tag | link_to_tag }}
{% else %}
{{ tag | link_to_tag }}
{% endif %}
{% elsif forloop.length > 2 %}
{% if forloop.last  %}
 and {{ tag | link_to_tag }}
{% elsif forloop.rindex == 2 %}
{{ tag | link_to_tag }}
{% else %}
{{ tag | link_to_tag }},
{% endif %}
{% endif %}
{% endfor %}

Yay! If you have any questions, feel free to ask. :)

/