Liquid conditional based off article tag

Shopify Partner
9 0 1

We've set up some sub-navigation for a blog based off of the way the articles are tagged so that each page would show only articles with certain tags (/blogs/blog-name/tagged/tag-name). However our client would like unique content at the top of each of these pages. I'm wondering if anyone might know of a way to create a conditional depending of the article tags or the end of the URL so that it would show in the event that we were on a particular page. Or if anyone has any other suggestions on how we might allow for the unique content for each of these different pages.

0 Likes
Shopify Partner
9 0 1

I was thinking about using something like {% if blog.url contains == 'tag-name' %} content here {% endif %}

But this didn't seem to work. If anyone has any suggestions I'd really appreciate it.

0 Likes
Astronaut
1890 1 393

Perhaps this is what you're looking for:

{% if article.tags contains "tag-shoes" %}
  Unique content related to shoes goes here.
{% endif %}

 

0 Likes
Shopify Partner
9 0 1

Thanks for the reply Alex. I tried this but it doesn't seem to work.

0 Likes
Shopify Partner
9 0 1

Ok. I figured it out using the current_tags liquid object.

For instance, on the the page with articles tagged videos:

{% if current_tags contains 'videos' %}

<h2>Videos</h2>

{% endif %}

I just added a conditional for each filter item (tag) and applied the content.

0 Likes
New Member
1 0 0

This works for me:

 

{% for tag in article.tags %}
{% if tag contains 'yourtag' %}
<p>custom content goes here </p>
{% endif %}
{% endfor %}

0 Likes