Show collections on a page based on keyword

Solved

Show collections on a page based on keyword

stormeagle
Excursionist
17 0 4

Does anyone have an approach for showing collections on a page based on keyword?

 

For example, if I have 1,000 collections and I want to list 50 of them on a page that have keyword "poster" in their title, how can I do that?

 

Right now my theme has a nice widget for manually choosing collections to list on a page, but for 50 that's a lot of tedious work. I'd like to automate this sort of thing.

 

Has anybody found an app for dynamically showing collections on a page based on filters?

Accepted Solution (1)

Flair-Liam
Shopify Partner
15 1 2

This is an accepted solution.

Hi, 

If you are referring to the main collection list we could use the liquid contains filter inside the collection for loop. For example

{%- for collection in collections -%}
  {%- if collection.title contains 'poster' -%}  <!-- This filters collections with 'poster' in the title -->
      <li class="collection-list__item grid__item {% unless collection.featured_image != blank %} no-image__item{% endunless %}">
        <!-- Your existing code for displaying the collection goes here -->
      </li>
  {%- endif -%}
{%- endfor -%}

 

Shopify Theme Developer
Flairconsultancy.com
[email protected]

View solution in original post

Replies 3 (3)

Flair-Liam
Shopify Partner
15 1 2

This is an accepted solution.

Hi, 

If you are referring to the main collection list we could use the liquid contains filter inside the collection for loop. For example

{%- for collection in collections -%}
  {%- if collection.title contains 'poster' -%}  <!-- This filters collections with 'poster' in the title -->
      <li class="collection-list__item grid__item {% unless collection.featured_image != blank %} no-image__item{% endunless %}">
        <!-- Your existing code for displaying the collection goes here -->
      </li>
  {%- endif -%}
{%- endfor -%}

 

Shopify Theme Developer
Flairconsultancy.com
[email protected]
stormeagle
Excursionist
17 0 4

Thank you. That's helpful.

 

I wish there was a way to insert Liquid code into page content without having to make a template just for that page.

Flair-Liam
Shopify Partner
15 1 2

No problem, yeah that would be helpful. 

If you need anything else just us know. 

 

Kind regards, Liam

Shopify Theme Developer
Flairconsultancy.com
[email protected]