Skip to content

Instantly share code, notes, and snippets.

@hezninja
Created June 20, 2022 01:05
Show Gist options
  • Save hezninja/edd959488a5a66520bb46c74c6a0283a to your computer and use it in GitHub Desktop.
Save hezninja/edd959488a5a66520bb46c74c6a0283a to your computer and use it in GitHub Desktop.
Shopify blog sub-menu using tags
<!--
Create a sub-menu for the blog based on specific tags, grouped by a prefix.
Example menu: "Yamaha | Suzuki | Harley-Davidson etc"
Method: Tag a blog post with "specificPrefix_Yamaha"
-->
{% assign brandedBlogTagList = '' %}
{% for blogTag in blog.all_tags %}
{% if blogTag contains "specificPrefix_" %}
{% assign brandedBlogTagList = brandedBlogTagList | append: ',' | append: blogTag %}
{% endif %}
{% endfor %}
{% assign brandedBlogTagList = brandedBlogTagList | remove_first: ',' | split: ',' %}
{% for brand in brandedBlogTagList %}
<a href="/blogs/blog/tagged/{{ brand | handleize }}">{{ brand | split: 'specificPrefix__' | last }}</a>
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment