Trying to create automated New Arrivals collection that contains 50 newest products

Tourist
28 0 1

Hello there, 

 

I have created a new template for my New Arrivals collection I'm working on based off of a few threads I've read on this forum. Here is my collection.newarrivals-collection.liquid template: 

{% section 'collection' %}

<!-- Published at {{product.created_at}} -->
{% if collection.title == 'New Arrivals' %}
{% for product in collection.products | limit: 50	%}
    {% assign date_published = product.created_at | date:'%s' %}
    {% assign date_now = 'now' | date:'%s' %}
    {% assign date_difference = date_now | minus: date_published %}

    {% if date_difference > 5184000 %}
       {% break %}
    {% endif %}
{% endfor %}
{% endif %}

I was hoping this would gather products created within the last 2 months, sorting from newest to oldest, and then limit the collection to only 50 products. I've been checking my collection in an incognito browser because I know there's a caching issue with the value 'now', though it seems to still not be functioning the way I want it to. The collection can be found here: https://www.triedequestrian.com/collections/new-arrivals-1?page=1

 

Any and all help is appreciated. Thank you!

0 Likes
New Member
2 0 1

where do we put this code?

1 Like
Tourist
4 0 0

I see you have this fixed at your store,


@skateboardp94 wrote:

Hello there, 

 

I have created a new template for my New Arrivals collection I'm working on based off of a few threads I've read on this forum. Here is my collection.newarrivals-collection.liquid template: 

{% section 'collection' %}

<!-- Published at {{product.created_at}} -->
{% if collection.title == 'New Arrivals' %}
{% for product in collection.products | limit: 50	%}
    {% assign date_published = product.created_at | date:'%s' %}
    {% assign date_now = 'now' | date:'%s' %}
    {% assign date_difference = date_now | minus: date_published %}

    {% if date_difference > 5184000 %}
       {% break %}
    {% endif %}
{% endfor %}
{% endif %}

I was hoping this would gather products created within the last 2 months, sorting from newest to oldest, and then limit the collection to only 50 products. I've been checking my collection in an incognito browser because I know there's a caching issue with the value 'now', though it seems to still not be functioning the way I want it to. The collection can be found here: https://www.triedequestrian.com/collections/new-arrivals-1?page=1

 

Any and all help is appreciated. Thank you!



How Exactly was this accomplished?   Can someone list the steps? Thank You!

0 Likes