Demonstrate Tag Page.
View this pattern on the live demo site
Tag archive page wrapping the tag-main section.
{% comment %}
Displays a tag page, including the tag name, image, description, and recent blog posts with the tag
{% endcomment -%}
{%- include "/_header.liquid" -%}
{%- include "/sections/_generic_banner.liquid" section_class:'text-bg-primary' -%}
{%- include "/sections/_breadcrumbs.liquid" -%}
{%- include "/sections/_tag_main.liquid" section_class:'text-bg-body' -%}
{%- include "/sections/_cta_snippet.liquid" section_class:'py-4 py-lg-5' -%}
{%- include "/_footer.liquid" -%}
Posts (or pages) tagged with this topic.
{% comment %}
Displays tag information and blog post cards for a tag.
Inputs:
page_param - the query parameter to use for pagination links. Defaults to 'page'
limit - the number of blog posts to show. Defaults to 12
exclude_current_tag - true to exclude the tag from being displayed on the blog post cards
Inputs passed through to _blog_feed.liquid:
section_class
section_id
+ any inputs passed through to child templates (eg: _pagination.liquid, _blogpost_card.liquid, etc...)
Custom Fields:
show_sidebar
show_sidebar_search
sidebar_related_content
sidebar_related_content_title
Outputs:
section_rendered - true when this section outputs markup, false otherwise
{% endcomment -%}
{%- if entity.object_type == 'tag' -%}
{%- var tag = entity -%}
{%- var page_param = page_param | default:'page' -%}
{%- var pageNum = request.query_params[page_param] | default:1 | to_int | at_least:1 -%}
{%- var limit = limit | default:12 | to_int | at_least:3 -%}
{%- blog_posts var posts = tag:entity page:pageNum sort_by:"post_date" sort_direction:"desc" limit:limit -%}
{%- var exclude_tag = '' %}{% if exclude_current_tag %}{% set exclude_tag = entity %}{% endif -%}
{%- var exclude_author = '' -%}
{%- var headinglevel = headinglevel %}{% comment %}Copy to current scope{% endcomment -%}
{%- capture var blog_feed_header -%}
{%- if pageNum > 1 -%}
<div class="container pt-4">
{%- include '/common/_title.liquid' title:entity.title title_classname:'text-center text-primary mt-3 mb-4' postincrement_headinglevel:true -%}
</div>
{%- elsif entity.description.is_valid -%}
<div class="container pt-4 pt-lg-5">
<div class="text-center text-muted mx-auto mb-0" style="max-width: 40rem;">{{ entity.description }}</div>
</div>
{%- endif -%}
<hr class="text-primary my-4">
{%- endcapture -%}
{%- var sidebar_recent_posts_title = 'Other Recent Posts' -%}
{%- assign sidebar_recent_posts_count = 5 -%}
{%- var sidebar_topics_title = 'Related Topics' -%}
{%- unless sidebar_topics is_valid -%}
{%- var taglist = null -%}
{%- include '/common/_taglist_from_items.liquid' items:posts max_tags:12 taglist_autofill_with_random:true exclude_tag:entity -%}
{%- assign sidebar_topics = taglist -%}
{%- endunless -%}
{%- include '/partials/_blog_feed.liquid' only_show_header_on_first_page:false show_sidebar:entity.show_sidebar.on show_sidebar_search:entity.show_sidebar_search.on sidebar_related_content:entity.sidebar_related_content sidebar_related_content_title:entity.sidebar_related_content_title -%}
{%- set section_rendered = true -%}
{%- else -%}
{%- set section_rendered = false -%}
{%- endif -%}Custom fields owned by the tag listing section.
[
{
"Type": "toggle",
"FieldID": "show_sidebar",
"Label": "Show Sidebar",
"OnValue": "show",
"OffValue": "hide",
"OnColor": "green",
"OffColor": "red",
"OnLabel": "Show",
"OffLabel": "Hide",
"DefaultValue": true
},
{
"Type": "group",
"Label": "Sidebar Content",
"Condition": {
"Type": "exists",
"FieldID": "show_sidebar"
},
"Fields": [
{
"Type": "toggle",
"FieldID": "show_sidebar_search",
"Label": "Show Sidebar Search",
"DefaultValue": true,
"OnValue": "show",
"OffValue": "hide",
"OnColor": "green",
"OffColor": "red",
"OnLabel": "Show",
"OffLabel": "Hide"
},
{
"Type": "entitylist",
"FieldID": "sidebar_related_content",
"HasUrl": true
},
{
"Type": "text",
"FieldID": "sidebar_related_content_title",
"Label": "Sidebar Related Content Title",
"DefaultValue": "Related Content",
"IsRequired": true,
"Condition": {
"Type": "exists",
"FieldID": "sidebar_related_content"
}
}
]
}
]
Posts with this tag as a feed with optional sidebar.
{% comment %}
Outputs a blog feed section with the given blog posts displayed as a list of cards.
Inputs:
section_class - an optional classname to apply to the section
section_id - an optional id to apply to the section
blog_feed_header - optional markup to include as the header above the blog feed
only_show_header_on_first_page - false to allow the header to be displayed past the first page of the collection
posts - the collection of blog posts to output
show_sidebar - true to show the blog sidebar next to the blog posts
empty_posts_html - optional markup when there are no posts to display
Inputs passed through to _blog_sidebar.liquid:
show_sidebar_search - when true, show the sidebar search widget
Inputs passed through to /common/_pagination.liquid:
page_param
Inputs passed through to _blogpost_card.liquid:
show_authors - true to show the blog post's authors in the card footer
show_tags - true to show the blog post's tags
card_classes (optional) - additional classes to include on <div class="card">
If show_sidebar is true, all relevant inputs are passed through to /partials/_blog_sidebar.liquid.
Additionally, sidebar_recent_posts_exclude is automatically updated to exclude all of the posts
{% endcomment -%}
<section{% if section_class %} class="{{ section_class }}"{% endif %}{% if section_id %} id="{{ section_id }}"{% endif %}>
{%- if blog_feed_header is_valid %}{% if posts.page == 1 or only_show_header_on_first_page == false %}{{blog_feed_header}}{% endif %}{% endif -%}
{%- var post_cols = 3 -%}
<div class="container py-4 py-lg-5">
{%- if show_sidebar -%}
<div class="row g-4 g-lg-5 align-items-start">
<div class="col-12 col-lg-8 order-2 order-lg-1">
{%- set post_cols = 2 -%}
{%- endif -%}
{%- if posts.is_valid and posts.size > 0 -%}
{%- comment %}
Use the following to display the blog feed as rows instead of cards:
{%- include "/partials/_blog_feed_rows.liquid" -%}
{% endcomment -%}
{%- include "/partials/_blog_feed_cards.liquid" -%}
{%- else -%}
<div class="text-center py-5 px-3 rounded-4 text-bg-light border">
{%- if empty_posts_html is_valid -%}
{{ empty_posts_html }}
{%- else -%}
<p class="h4 text-primary mb-3">No matching posts found</p>
{%- if show_sidebar -%}
<p class="text-muted mb-0">Try another search, or browse recent posts and topics in the sidebar.</p>
{%- endif -%}
{%- endif -%}
</div>
{%- endif -%}
{%- if show_sidebar -%}
</div>
<div class="col-12 col-lg-4 order-1 order-lg-2">
{%- var sidebar_recent_posts_exclude = sidebar_recent_posts_exclude | default: '' -%}
{%- if posts.is_valid %}{% set sidebar_recent_posts_exclude = sidebar_recent_posts_exclude | concat:posts %}{% endif -%}
{%- include '/partials/_blog_sidebar.liquid' -%}
</div>
</div>
{%- endif -%}
</div>
{%- if posts.is_valid and posts.size > 0 -%}
<div class="container mb-4">
{%- include '/common/_pagination.liquid' collection:posts pagination_justify:'center' -%}
</div>
{%- endif -%}
</section>