Show product collection on blog post

Solved
Highlighted
New Member
5 0 0

Hi all,

I'm trying to show a product collection at the bottom of a blog post, where the tag of the blog post is equal to the handle of the collection. Here is what I have so far: 

{% assign tag = article.tags %}
<h4>Shop {{ tag }}</h4>
{% for product in collections[tag].products limit:3 %}

{% include 'product-grid-item' %}

{% endfor %}

If I chang the variable for tag to equal the name of a collection, say "accessories" instead of article.tags, it works fine.

Any help would be appreciated.

Thanks!

 

0 Likes
Highlighted
Shopify Expert
44 1 9

This is an accepted solution.

I'm pretty sure this is because article.tags is an array of tags associated with the article, instead of just one tag. You could probably do something like article.tags.first or article.tags.last to get the first/last tag. I'm not sure if the order of tags in the array is alphabetical or based on when you added the tag, though. If you only have 1 tag per article this will work regardless.

Austin 

0 Likes
Highlighted
New Member
5 0 0

Thanks for the tip, Austin!

I was only using 1 tag, but even so adding the .first made it work.

Cheers!

0 Likes
Highlighted
New Member
1 0 2

I'm so glad I found this thread! I'm desperately trying to have related products show in my blog posts. I tried the above with little success. The Shop 'collection name' appeared with the first tag but no link or products . . . Any advice or help would be hugely appreciated!

2 Likes
Highlighted
New Member
2 0 0
I don't know any coding but want to add a collection to end of my blog posts too. Do you have a simple set of instructions I could follow? Thanks
0 Likes
Highlighted