Ad

How To Filter All Blog.Articles By Containing Specific Tag In Shopify?

- 1 answer

hello is there anyone shopify experts out there . my only goal is to filter or display all articles according to their tag .

so this is what i have so far from this forum

{% assign counter = 0 %}
{% for article in blogs['lookbook'].articles %}
{% if article.tags contains 'Fox Racing' and counter < 2 %}
  {% assign counter = counter | plus: 1 %}
          <div class="njohn_search_otherpage">
          <a target="_blank" rel="nofollow noreferrer" href="{{ article.url }}" title="{{ article.title | escape }}">
              <div>{{ article.image.src | img_url: 'medium' | img_tag: article.title }}</div>
              <div>{{ article.title }}</div>
          </a>
          </div>
{% endif %}
{% endfor %}

the code are working but it's only four article will showed up. but in that sample tag i have already 10 articles.

Ad

Answer

The above code has a counter that limits the articles displayed, removing that counter works as expected, filtering all the articles by a tag.

{% for article in blogs['lookbook'].articles %} 
{% if article.tags contains 'Fox Racing' %} 
<div class="njohn_search_otherpage"> <a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{{ article.url }}" title="{{ article.title | escape }}"> <div>{{ article.image.src | img_url: 'medium' | img_tag: article.title }}</div> <div>{{ article.title }}</div> </a> </div>
 {% endif %} 
 {% endfor %}
Ad
source: stackoverflow.com
Ad