1
votes

I am building a theme in Shopify and struggling to get resources or find helpful documentation elsewhere, on how to show all blog posts that are within a specified category. I am referring to category where Shopify have called it blog.

I have created 10 or so blog posts: Some in a blog / 'category' called news. Some in a blog / 'category' called events.

enter image description here

So I am trying to find out how to loop through just the posts within one of the categories of blog.

But if you research 'shopify: how to show blog posts in only one category' you find respondents saying Shopify doesn't categorise posts, with no helpful content.

So you research 'shopify: how to show all blog posts from one blog' you effectively break the internet.

I am trying to find out how I replace the FOR loop within the blog.liquid script to show just one type of blog that gets specified. Such as news. If you could expand on how you find best to set up the page that will display these posts too would be really good too.

My current understanding would be to create a News page. Having its own page template page.news.liquid. Creating a blog.news.liquid file with the correct loop written within. Then including the blog.news.liquid file into the page.news.liquid file.

I have had a couple goes at this and it's really not worth me showing you what I have done, considering my level of ability in other CMS's I just cannot get my head around this or find the correct documentation.

1

1 Answers

1
votes

There's a global variable called blogs

{% for blog in blogs %}
  {% for article in blog.articles %}
    {{ article.title }}
  {% endfor %} 
{% endfor %}

Or show a single blog by using its handle (blog2) and pluralising the leading blog to become blogs:

{% for article in blogs.blog2.articles %}
  {{ article.title }}
{% endfor %} 

https://community.shopify.com/c/Shopify-Design/Liquid-Iterate-Through-All-Articles-in-All-Blogs/td-p/516244