Show newest products in section on homepage

Solved

Show newest products in section on homepage

Aidin3000
Shopify Partner
4 0 1

I am trying to create a section on the home page to show newest products published using the following code, however I am not getting accurate data:

 

assign all_products = collections.all.products | sort: 'published_at' | reverse

 

It's just not giving me the latest products compared to when I go to the All Collection sort by Date New to Old

 

Here is how I am rendering the products:

 

{% liquid
                    for product in all_products limit: section.settings.limit
                        render 'product-item', product: product
                    endfor
                %}

What could be the issue?

Accepted Solution (1)

goldi1
Excursionist
118 10 23

This is an accepted solution.

Hello @Aidin3000 

replace your code with this code 

and check it 

{% assign newest_products = collections['newest-products'].products | sort: 'published_at' | reverse %}

{% for product in newest_products limit: section.settings.limit %}
{% render 'product-item', product: product %}
{% endfor %}
Was I helpful?

Buy me a coffee



Want to modify or custom changes or bug fix on store . Or Need help with your store? Or -Want Complete Storefront
Email me -rahul@prowebcoder.com - Skype: live:dhiman.639
Whatsapp Me : here

View solution in original post

Replies 3 (3)

goldi1
Excursionist
118 10 23

This is an accepted solution.

Hello @Aidin3000 

replace your code with this code 

and check it 

{% assign newest_products = collections['newest-products'].products | sort: 'published_at' | reverse %}

{% for product in newest_products limit: section.settings.limit %}
{% render 'product-item', product: product %}
{% endfor %}
Was I helpful?

Buy me a coffee



Want to modify or custom changes or bug fix on store . Or Need help with your store? Or -Want Complete Storefront
Email me -rahul@prowebcoder.com - Skype: live:dhiman.639
Whatsapp Me : here
Aidin3000
Shopify Partner
4 0 1

This worked but I had to create a collection called Newest Products that listed all products for it to work.

 

Any reason this didnt work with the All collection?

 

Thank you.

goldi1
Excursionist
118 10 23

ok thanxx let me try it 

if you think i was helpful could you buy me a coffee ??

Was I helpful?

Buy me a coffee



Want to modify or custom changes or bug fix on store . Or Need help with your store? Or -Want Complete Storefront
Email me -rahul@prowebcoder.com - Skype: live:dhiman.639
Whatsapp Me : here