How to sort product titles when I output products in a collection?

Solved
Highlighted
Explorer
96 0 4

Hi,

 

I'm trying to output all the product titles in a specified collection, and adding a link to that title. 

  {% for product in collections.SomeCollection.products %}
    <a href="Some-Link">{{ product.title }}</a>
  {% endfor %}

How can I sort the product results by title? Below code is ballpark what I think I'm looking for but it doesn't work.

  {% for product in collections.SomeCollection.products | sort: 'title' %}
    <a href="Some-Link">{{ product.title }}</a>
  {% endfor %}

Any ideas? Thanks!

0 Likes
Highlighted
Shopify Partner
591 92 133

This is an accepted solution.

Hello @tesstesting

Try this

{% assign products = collections.SomeCollection.products | sort: 'title' %}
{% for product in products %}
<a href="link">{{ product.title }}</a>
{% endfor %}

1 Like
Highlighted
Explorer
96 0 4

@wahab 

 

This worked perfectly thank you.

1 Like
Highlighted
New Member
8 0 0

Capture.JPGKindly help me i need option Availability on sort by menu

0 Likes