Demonstrate Blog Feed.
View this pattern on the live demo site
Card grid used when a blog feed needs a compact post list.
{% comment %}
Outputs blog posts as a responsive card grid
Inputs:
posts - the blog posts to output
post_cols - The maximum number of blog posts to display per row. Defaults to 2.
Inputs passed through to _blogpost_card.liquid:
show_authors - true to show the blog post's authors in the card footer
exclude_author - if included, the selected author will NOT be shown in the card footer
show_tags - true to show the blog post's tags
exclude_tag - if included, the selected tag will NOT be shown
card_classes (optional) - additional classes to include on <div class="card">
{% endcomment -%}
{%- var post_cols = post_cols | to_int | default: 2 | at_least: 1 | at_most: 6 -%}
{%- if posts.size == 1 -%}
{%- set post_cols = 1 -%}
{%- endif -%}
{%- var row_classes = 'row-cols-1' -%}
{%- if post_cols == 1 -%}
{%- set row_classes = 'justify-content-center' -%}
{%- else -%}
{%- set row_classes = 'row-cols-1 row-cols-md-' | append: post_cols -%}
{%- endif -%}
<div class="row g-4 {{row_classes}}">
{%- for post in posts -%}
<div class="col{% if post_cols == 1 %} col-md-8 col-xl-7{% endif %}">
{%- include "/partials/_blogpost_card.liquid" card_classes:'h-100 border-0 shadow-sm' -%}
</div>
{%- endfor -%}
</div>One post card: image, tags, title, summary, and optional authors.
{% comment %}
This template should be used to display a single blog post as a card.
Inputs:
post - the post to be displayed
show_authors - true to show the blog post's authors in the card footer
exclude_author - if included, the selected author will NOT be shown in the card footer
show_tags - true to show the blog post's tags
exclude_tag - if included, the selected tag will NOT be shown
card_classes (optional) - additional classes to include on <div class="card">
img_preset_blog_thumb - The image preset to use for the blogpost thumbnail
{% endcomment -%}
{%- if post.is_valid -%}
{%- var show_authors = show_authors | default:true -%}
{%- var show_tags = show_tags | default:true -%}
{%- var tags = '' %}{% if show_tags and post.tags.is_valid %}{% if exclude_tag is_valid %}{% tags set tags = unique:true prepend:exclude_tag append:post.tags %}{% set tags = tags.appended_unique %}{% else %}{% set tags = post.tags %}{% endif %}{% endif -%}
{%- var authors = '' %}{% if show_authors and post.authors.is_valid %}{% if exclude_author is_valid %}{% authors set authors = unique:true prepend:exclude_author append:post.authors %}{% set authors = authors.appended_unique %}{% else %}{% set authors = post.authors %}{% endif %}{% endif -%}
<div class="card overflow-hidden position-relative{% if card_classes is_valid %} {{card_classes}}{% endif %}">
{%- if post.image.is_valid -%}
{%- img post.image link:false class:'card-img-top' style:'aspect-ratio: 16 / 10; object-fit: cover;' preset:img_preset_blog_thumb -%}
{%- endif -%}
<div class="card-body d-flex flex-column">
{%- if tags is_valid -%}
<div class="mb-2">
{%- include '/common/_entity_list_simple.liquid' entities:tags entities_join: ' ' entity_link_class:'badge rounded-pill text-bg-secondary text-decoration-none me-1 mb-1' entity_link_style:'position:relative;z-index:2' -%}
</div>
{%- endif -%}
<div class="h5 card-title mb-2">
{%- if post.has_url -%}
<a href="{{post.full_url}}" class="text-reset text-decoration-none stretched-link">{{post.title}}</a>
{%- else -%}
{{post.title}}
{%- endif -%}
</div>
<p class="card-text text-muted small mb-0 flex-grow-1">{{ post.summary_html | default: post.content_html | strip_html | html_decode | strip | truncate_to_word: 180 | escape }}</p>
</div>
{%- if authors is_valid -%}
<div class="card-footer bg-transparent border-0 pt-0">
{%- for author in authors -%}
{%- include '/partials/_person_profile.liquid' layout:'inline' img_preset_person_thumb:img_preset_author_thumb show_card:false show_link:true use_stretched_link:true title_classname:'text-reset fw-bold small mb-0' title_link_classname:'text-reset text-decoration-none' -%}
{%- endfor -%}
</div>
{%- endif -%}
</div>
{%- endif %}