A space to discuss online store customization, theme development, and Liquid templating.
Hello dear,
i want create a custom blog filter by featured, old to new, new to old, a-z, and a-z. without app
Please help how can create this
Thanks and regard
here is an example
<form>
<label for="sort-by">Sort By:</label>
<select id="sort-by" name="sort-by">
<option value="featured">Featured</option>
<option value="old-new">Old to New</option>
<option value="new-old">New to Old</option>
<option value="a-z">A-Z</option>
<option value="z-a">Z-A</option>
</select>
<input type="submit" value="Sort">
</form>
{% assign posts = blog.articles %}
{% case sort-by %}
{% when 'featured' %}
{% assign posts = blog.articles | where: 'featured', true %}
{% when 'old-new' %}
{% assign posts = blog.articles | sort: 'published_at' %}
{% when 'new-old' %}
{% assign posts = blog.articles | sort: 'published_at' | reverse %}
{% when 'a-z' %}
{% assign posts = blog.articles | sort: 'title' %}
{% when 'z-a' %}
{% assign posts = blog.articles | sort: 'title' | reverse %}
{% endcase %}
{% for post in posts %}
... code to display each blog post ...
{% endfor %}
If this fixed your issue, likes and accepting as a solution are highly appreciated
| Build an online presence with our custom-built Shopify Theme: EcomifyTheme
| Check out our reviews: Trustpilot Reviews
| We are Shopify Partners: EcomGraduates Shopify Partner
doesn't work on sort button click any other solution?