Hello!
I would like to add navigation to my blog so that people can quickly access blog posts based on tags.
Is there an easy way to do this?
Thanks!
A Shopify user seeks to add tag-based navigation to their blog using the Dawn theme, allowing readers to filter posts by topic.
Initial Solution:
article.tags to display clickable tags on individual blog postsRefinement:
blog.tags instead of article.tags, displaying the complete tag collection across all postsStyling Enhancement:
Alternative Approach:
Status: Resolved. The custom code solution successfully implements tag navigation with styled buttons. Code snippets and screenshots were central to the troubleshooting process.
Hello!
I would like to add navigation to my blog so that people can quickly access blog posts based on tags.
Is there an easy way to do this?
Thanks!
Hi @Jodiebe . Do you want something like this?
It is a article page. It is showing all the tags of the article which is clickable. Upon click it will redirect you to the page where you can view all the articles with that tag.
You can use the following code in your main-article.liquid file.
{% for tag in article.tags %}
{{ tag | capitalize}}
{% endfor %}
Let us know if this works for you or not.
Thank you for the reply but that didn’t seem to work. Is there a particular spot in the main-article.liquid file where that code needs to go?
@BrainStation23 - I can see how this solution will show the specific tag for a specific blog post, which then links to other blog posts with the same tag.
But is there a way to have all the tags represented on a blog post so people can click through to any of the tags from any of the blog posts?
I’m using the Dawn theme.
Thanks!
Can you share your main-article.liquid file?
Not sure whether fully understood your question. But you’ve article.tags to access all the tags of a specific article and blog.tags to access all the tags of a specific blog.
Thank you for clarifying. Is there a way for all blog.tags (all the tags of a specific blog) to appear on every blog post?
{{ ‘section-blog-post.css’ | asset_url | stylesheet_tag }}
{%- for block in section.blocks -%} {%- case block.type -%} {%- when '@app' -%}{%- when ‘title’ -%}
{%- when ‘content’ -%}
{%- when ‘share’ -%}
{%- for comment in article.comments -%}
{{ comment.content }} {{ comment.author }} {{- comment.created_at | time_tag: format: 'date' -}} {%- endfor -%} {% render 'pagination', paginate: paginate, anchor: anchorId %}{{ 'blogs.article.moderated' | t }}
{%- endif -%} {% endform %}{% schema %}
{
“name”: “t:sections.main-article.name”,
“tag”: “section”,
“class”: “section”,
“blocks”: [
{
“type”: “@app”
},
{
“type”: “featured_image”,
“name”: “t:sections.main-article.blocks.featured_image.name”,
“limit”: 1,
“settings”: [
{
“type”: “select”,
“id”: “image_height”,
“options”: [
{
“value”: “adapt”,
“label”: “t:sections.main-article.blocks.featured_image.settings.image_height.options__1.label”
},
{
“value”: “small”,
“label”: “t:sections.main-article.blocks.featured_image.settings.image_height.options__2.label”
},
{
“value”: “medium”,
“label”: “t:sections.main-article.blocks.featured_image.settings.image_height.options__3.label”
},
{
“value”: “large”,
“label”: “t:sections.main-article.blocks.featured_image.settings.image_height.options__4.label”
}
],
“default”: “adapt”,
“label”: “t:sections.main-article.blocks.featured_image.settings.image_height.label”,
“info”: “t:sections.main-article.blocks.featured_image.settings.image_height.info”
}
]
},
{
“type”: “title”,
“name”: “t:sections.main-article.blocks.title.name”,
“limit”: 1,
“settings”: [
{
“type”: “checkbox”,
“id”: “blog_show_date”,
“default”: true,
“label”: “t:sections.main-article.blocks.title.settings.blog_show_date.label”
},
{
“type”: “checkbox”,
“id”: “blog_show_author”,
“default”: false,
“label”: “t:sections.main-article.blocks.title.settings.blog_show_author.label”
}
]
},
{
“type”: “content”,
“name”: “t:sections.main-article.blocks.content.name”,
“limit”: 1
},
{
“type”: “share”,
“name”: “t:sections.main-article.blocks.share.name”,
“limit”: 2,
“settings”: [
{
“type”: “text”,
“id”: “share_label”,
“label”: “t:sections.main-article.blocks.share.settings.text.label”,
“default”: “Share”
},
{
“type”: “paragraph”,
“content”: “t:sections.main-article.blocks.share.settings.featured_image_info.content”
},
{
“type”: “paragraph”,
“content”: “t:sections.main-article.blocks.share.settings.title_info.content”
}
]
}
]
}
{% endschema %}
{% for tag in blog.tags %}
{{ tag | capitalize}}
{% endfor %}
This is brilliant @BrainStation23 - thank you! The tags are in the right place now and all are showing. Is it possible for the tags to be buttons like in your first example rather than text only links?
You’re most welcome @Jodiebe . Glad to hear that. If our reply has helped you then please mark it as accepted and give it a like. Thanks.
Yes, will do. I just had one more question about whether the links can be buttons instead of text? Like in your original pic - like above? Thanks!
Sorry, didn’t notice your query. In the above image, those tags are actually links, but we’ve styled them to look like button.
You need to update the code like followings:
{{ tag | capitalize}}
Thank you!
Alternatively, you can try out one of those blog filter apps that uses tags to build dropdown style filtering, with built-in blog search ability.