Vendor: Set default sort for vendor query pages
This code change allows you to change the default Vendor link on product pages to a predetermined sorted version of the vendor query page.
Always make a duplicate of your theme before adding any code. This will save you if anything goes wrong or if you decide not to use the added code in the future. We can not support or be responsible of any code changes that you make to your theme. For that reason, save yourself and make a duplicate first.
Make a duplicate of your theme:
After you've duplicated your theme, you can continue with the following code change:
- 1
-
Add code to the snippets product.liquid file
Edit Snippets/product.liquid.
(1) In left folder view, use the search bar
(2) Find the file in the Snippets folder.
If you're working with your published theme, use this link:
Here's a quick link you can use if you're working with your live published theme:
https://shopify.com/admin/themes/current?key=snippets/product.liquid&line=80
Note - The quick links in our tutorials will always open the Code Editor for your live published theme. If you're working on an unpublished theme, always manually launch the Code Editor by using that theme's Actions link.
Find the following line (around line 80 in Pipeline 3):
Tip: In the code area, use the Find feature (Command-F on Mac, Control-F in Windows) and search for "vendor" without quotes.
Replace the following line:
<p><a href="{{ product.vendor | url_for_vendor }}" class="border-bottom-link uppercase">{{ product.vendor }}</a></p>
Replace with one of these options:
Option 1: Date newest to oldest
<p><a class="border-bottom-link uppercase "href="/collections/vendors?q={{ product.vendor }}&sort_by=created-descending">{{ product.vendor }}</a></p>
Option 2: Date oldest to newest
<p><a class="border-bottom-link uppercase "href="/collections/vendors?q={{ product.vendor }}&sort_by=created-ascending">{{ product.vendor }}</a></p>
Option 3: Price lowest to highest
<p><a class="border-bottom-link uppercase "href="/collections/vendors?q={{ product.vendor }}&sort_by=price-ascending">{{ product.vendor }}</a></p>
Option 4: Price highest to lowest
<p><a class="border-bottom-link uppercase "href="/collections/vendors?q={{ product.vendor }}&sort_by=price-descending">{{ product.vendor }}</a></p>
Option 5: Best setting
<p><a class="border-bottom-link uppercase "href="/collections/vendors?q={{ product.vendor }}&sort_by=best-selling">{{ product.vendor }}</a></p>
Option 6: Title Z-A
<p><a class="border-bottom-link uppercase "href="/collections/vendors?q={{ product.vendor }}&sort_by=title-descending">{{ product.vendor }}</a></p>
Note: The default sort type is Title A-Z, no change is needed for that.
Line to replace:
Save the file.
Undo
If you need to quickly undo the code change you can use the Older versions link or publish your duplicate/backup theme.
Need help with code changes?
We're not able to make any code customizations but we can recommend shophelper.io and heycarson -- they both specialize in small code changes and have really competitive flat-rate pricing.
Collection sidebar
To achieve the same result with Collection page sidebar links, make the following customization:
- 1
-
Edit the sidebar code
Open snippets/collection-sidebar.liquid:
https://shopify.com/admin/themes/current?key=snippets/collections-sidebar.liquid&line=88
Replace the following code in 2 places:
{{ vendor | link_to_vendor }}
Replace in both places with one of these options:
Option 1: Date newest to oldest
<a href="/collections/vendors?q={{ vendor }}&sort_by=created-descending">{{ vendor }}</a>
Option 2: Date oldest to newest
<a href="/collections/vendors?q={{ vendor }}&sort_by=created-ascending">{{ vendor }}</a>
Option 3: Price lowest to highest
<a href="/collections/vendors?q={{ vendor }}&sort_by=price-ascending">{{ vendor }}</a>
Option 4: Price highest to lowest
<a href="/collections/vendors?q={{ vendor }}&sort_by=price-descending">{{ vendor }}</a>
Option 5: Best setting
<a href="/collections/vendors?q={{ vendor }}&sort_by=best-selling">{{ vendor }}</a>
Option 6: Title Z-A
<a href="/collections/vendors?q={{ vendor }}&sort_by=title-descending">{{ vendor }}</a>
Example of 2 lines to change:
Save the file.