Ordering collections by letter, then number

Solved
New Member
2 0 1

Hello,

 

I'm relatively new to Shopify (and very new to liquid coding!) and wondered if anyone could help me with the following issue. I have edited the collection page to appear as an A-Z list of brands, which works well. However, I require the collection titles whose names start with a number to be placed at the bottom of the A-Z list instead of at the top.

 

Does anyone know if there is a way in Shopify to code this?

 

I am aware I could create a menu with all the collections in, and link to that instead, but setting up several hundred brands in this way, and then maintain the menu over time is really not ideal when at the moment the list is automatically generated.

 

Here's the section of code that controls the A-Z brand listing:

 

<!-- This code creates the list of brands -->
<ul class ="hoopers-a-z-brands">
{% assign current = "" %}
{% for collection in collections %}
  
  {% unless collection.title == 'Accessories' or collection.title == 'Beauty' or collection.title == 'Furniture' or collection.title == 'Gift Card' or collection.title == 'Home & Gifts' or collection.title == 'Ladies' or collection.title == 'Mens' or collection.title == 'Beauty Focus' or collection.title == 'Valentines Day' or collection.title == 'Fathers Day' or collection.title == 'Mothers Day' or collection.title == 'Home Event' or collection.title == 'Christmas' or collection.title == 'Fashion Focus' or collection.title == 'Lingerie Fortnight' %}

  {% assign first_letter = collection.title | strip_html | upcase | truncate: 1, '' %}
    {% unless first_letter == current %}
  <div class="clearfix"></div>
  <li class="brand-list-letter"><a name="{{ first_letter }}"></a>{{ first_letter }}</li>
    {% endunless %}
    <li class="collection-order"><a href="{{ collection.url }}" title="Discover {{ collection.title }} at Hoopers">{{ collection.title }}</a></li>  
  {% assign current = first_letter %}
  
  {% endunless %}
  
{% endfor %}
</ul>

Many thanks

Alex

1 Like

Hi Alex,

See how we have done it on one client store https://www.scentualpleasures.com

We have customized the menu to have alphabetical orders, price wise and other formats as well.

Please let me know if you need help on your menus.

Best Regards

Anand

We are a Shopify Partner Company
Built more than 100 Shopify Stores
Connect to me on m.me/firstwire or skype at anand@firstwireapp.com
Check portfolio at https://firstwireapp.com/shopify-services/
0 Likes
Highlighted

Success.

Shopify Partner
2495 15 465

Alex,

I would approach it in the following way -- duplicate the loop, and first skip collections with first letter being a digit, but in second loop break out when the first letter is not a digit:

 

{% for collection in collections %}
  {% assign first_letter = collection.title | strip_html | upcase | truncate: 1, '' %}
  {% if "0123456789" contains first_letter %}
    {% continue %}
{% endif %} ... output collection {% endfor %} {% for collection in collections %} {% assign first_letter = collection.title | strip_html | upcase | truncate: 1, '' %} {% unless "0123456789" contains first_letter %} {% break %}
{% endunless %} ... output collection {% endfor %}

 

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com! My post solved your problem? This is my Paypal too :)
1 Like
New Member
2 0 1

Hi Tim,

 

Thank you very much for this advice, it's always nice to learn something new... I can report this has worked a treat! 

 

Many thanks,

Alex

0 Likes