0
votes

I'm new to Shopify. I have 5 blog categories (using multiple blogs) and I need to find a way to show each post in its own blog category. My code is currently populating the news articles and displaying the same ones in every category. How can I rewrite my for loop to loop through each category and display the articles only related to that category.

  {% for article in blogs.news.articles %}
  {% assign content = article.content | split: '[/email]' %}
  <li class="widget-article">
    <div class="widget-image">
      <a href="{{ article.url }}">
        <img src="{{ article.image | article_img_url: 'original' }}" alt="">
      </a>
    </div><!-- /.widget-image -->

    <div class="widget-content">
      <h3 class="widget-title">{{ article.title }}</h3><!-- /.widget-title -->
      <p>
        {% if content[1] %}
        {{ content[1] | strip_html | truncatewords:15  }}
        {% else %}
        {{ content[0] | strip_html | truncatewords:15  }}
        {% endif %}
      </p>
    </div><!-- /.widget-content -->
  </li><!-- /.widget -->
  {% endfor %}

Thanks

1
Please define categoryButs

1 Answers

0
votes

When you write "category" do you mean collection? Are you trying to associate a blog with a collection? If that's what you are trying to do then one way is to give the blog and collection the same handle.

then you could add your code to your collection template (I'd suggest as a snippet) and the snippet would start like:

{% assign blog = blogs[collection.handle] %}
{% if blog  %}
   <div class='blog-wrap'>...
      {% for article in blog.articles %}