Skip to documentation content

Blog Feed

All complete examples

Demonstrate Blog Feed.

What this example teaches

  • Use Blog Feed as a reusable Liquid component
  • Keep custom fields on the template that owns them

View this pattern on the live demo site

Files

Card grid used when a blog feed needs a compact post list.

Liquid
{% 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>