I’m trying to show a list of Blog Articles on each Collection page that has the same Product Tags used to poluate each Collection. For example, I have a Collection created to show Products with the Product Tag ‘Apple’. I then want to show a list of all the Blog Articles on that Apple Collection page that have the Article Tag ‘Apple’.
This is the code I have written. I’m trying to Capture the Product Tag and then get the code to use this Product Tag to find all the Blog Articles I have written with the same Tag.
I can get the Capture to capture the correct Product Tag {{ prod_tag }} but I cannot use the Capture in the next code I have to find the Blog Articles.
Can anyone help? I’m really stuck on this one. Thanks
This is all the code…
{% capture prod_tag %}
{% for tag in current_tags %}
{{ tag | remove: ‘brands_’ | replace: ‘-’, ’ ’ }}
{% endfor %}
{% endcapture %}
{{ prod_tag }} <— this is just a test for me to see that I the capture code works
Thanks for your reply. I tried that just now but still not working.
Strange as the Capture code I’ve written does give the right results as shown in my screenshot. However, when I add the ‘prod_tag’ to the article code below this (green) it doesn’t work at all.
In green your text says “shows correct tags”; plural. What is the output of prod_tag? If it is capturing multiple Tags then you need to capture and create an array, then step thru both arrays : a) loop thru the Article’s Tags and then for each in turn, b) loop thru the captured Tags — to check for each Article Tag whether any of the capatured Tags matches.
e.g. if Article Tags contains “bananas, apples” and prod_tag contains “oranges, apples” you will need to loop so that the iterations are as follows:
Here is the code that I used on the Dawn theme. It works fine.
So I’m pulling the collection handle and splitting it into multiple words and if the article title matches any of those words it will put that article on the collection page. Here is the code:
{% for article in blogs[‘your-blog-handle’].articles %}
{% if article.handle contains collection_handle.first or article.handle contains collection_handle[1] %}
{% if article_count < 3 %}