How can I display multiple products on a blog post?

How can I display multiple products on a blog post?

JoshSpires
Tourist
13 0 1

I am working on displaying products on blog posts and have managed to get a single product to display.

 

Is there a way to get all products to display?

The code I'm using: (It looks at the tags in blog post, finds the one containing product_[product name] and displays it.

 

{%- liquid
    for tag in article.tags
        if tag contains "product_"
            assign prod_handle = tag | split: "_"
            assign blog_prod = all_products[prod_handle[1]]
        endif
    endfor
%}
            
{% if blog_prod %}
    <h2>Recommended solutions</h2>
    <div class="boost-pfs-filter-products boost-pfs-filter-product-item-label-type-rectangle boost-pfs-filter-product-item-label-has-border boost-pfs-filter-product-item-show-details-false boost-pfs-filter-product-item-layout-border-no-padding boost-pfs-filter-product-item-label-top_left boost-pfs-filter-product-item-swatch_color_display_type_image_product boost-pfs-filter-swatch-shape-circle boost-pfs-filter-product-item-text-alignment-left">
        {% include 'use-case-product-grid-item' %}
    </div>
{% endif %}

 

 

Josh Spires
Replies 2 (2)

SheetalZadfiya
Explorer
70 15 19

Hi @JoshSpires 

 

I understood your concern. I came to know that you can achieve it using custom code.

Please add the below code to the file

 

 

{% assign allhandles =''%}
{%- liquid
    for tag in article.tags
        if tag contains "product_"
            assign prod_handle = tag | split: "_"
            assign blog_prod = prod_handle[1]
            assign allhandles = allhandles | append: ',' | append: blog_prod
        endif
    endfor
%}
{% assign newTagList = allhandles | remove_first: ',' | split: ',' %}
{%- for tag in newTagList -%}
{%- assign product = all_products[tag] -%}
{%- include 'product-grid-item' -%}
{%-  endfor  -%}

 

 

I hope it's helpful to you.

If our answer is helpful then please feel free to Like and Accept it as solution!
Hire our Shopify Developers for all your small & big needs:
New Store Development | Custom Theme Development | Site Speed Optimization
Email: hello@mintyourstore.com | Instagram: @mintyourstore

Aurnik
Shopify Partner
51 1 4

If you want a way to display products in a blog post just using the normal blog editor, I made an app that lets you embed multiple products into your posts.

https://apps.shopify.com/product-embed

Product Embed - embed products into blog posts - shopify.com/product-embed
Blog Sync - copy new & updated blog posts across stores - shopify.com/blog-sync