With some inverse modification to continue(autoskip ) part of a loop, you would take the logic you’ve put together and find the article loop in whatever the “blog section” is for your specific theme. And wrap that logic with your logic.
Do the tag check like your doing but when it’s NOT a match use the {% continue%} tags to make the current article that doesn’t have a tag match get skipped.
{% if article.tags contains product_handle %}
{{ article.image.src | img_url: 'large' | img_tag: article.title }}
{{ article.title }}
{% else %}
{% continue %}
{% comment %} The rest of the default article code goes here inside the else & endif {% endcomment %}
{% endif %}
Keeping in mind that contains makes matching tags fuzzy so trying to match “contains red” would also match any tag with those characters so a “credit” tag would create a false positive.
If I could change [“blog”: “news”] to a dynamic data like [“blog”: “{{ product.handle }}”] , then I could use a different blog for every product. That would work for me.
Bu I tried to use [“blog”: “{{ product.handle }}”] and it doesn’t work. The Shopify code editor says : can’t include Liquid syntax (‘{{’, ‘}}’, ‘{%’ or ‘%}’) “without valid dynamic sources”
Hi, I’m looking for a solution like this. Where do you put the above code? I placed it in my “Custom Liquid” section for my Product Page but it’s not working. Am I missing something?
You have to modify the underlying code itself that shows the blog articles for your specific theme, it’s not done by arbitrarily adding custom-liquid theme settings.
Custom-liquid setting would primarily be to design and make a completely custom blog/article display.
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 %}