Skip to documentation content

Blog Sidebar

All complete examples

Demonstrate Blog Sidebar.

What this example teaches

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

View this pattern on the live demo site

Files

Sidebar stack (topics, CTA, related posts) included from blog layouts.

Liquid
{% comment %}
	Displays a sidebar next to blog posts and other blog content.

	This template makes one additional modification to the input, which is that if there is both related content and recent posts, the related content will automatically be excluded from recent posts

	Inputs:
		show_sidebar_search - The sidebar serach will only be displayed when this is true
	
	Inputs passed through to the search widget:
		sidebar_search_target - the URL to submit searches to. Must be specified for the searchform to be displayed
		sidebar_search_title - the title for the search widget. Optional
		sidebar_search_param - The query parameter to use for the search term. Defaults to 'q'
		sidebar_search_placeholder - The placeholder to use in the search field
		search_term - optional current search term to prefill the form

	Inputs passed through to the related content widget:
		sidebar_related_content - the list of related content to display in the sidebar
		sidebar_related_content_title - the title for the related content widget. Optional

	Inputs passed through to the context widget:
		sidebar_context_title - optional title for context content
		sidebar_context_html - optional HTML content for context content

	Inputs passed through to the topics widget:
		sidebar_topics - optional list of topics/tags to display
		sidebar_topics_title - optional title for the topics widget

	Inputs passed through to the recent posts widget:
		sidebar_recent_posts_count - the number of recent posts to display. If not specified, the recent posts will not be displayed
		sidebar_recent_posts_title - the title for the recent posts widget. Optional
		sidebar_recent_posts_exclude - posts to exclude from the recent posts
		sidebar_recent_posts_filters - filters to use for the recent posts.

	Inputs passed through to the CTA widget:
		none. It uses custom fields instead
{% endcomment -%}
{%- if sidebar_related_content is_valid and sidebar_recent_posts_count is_int and sidebar_recent_posts_count > 0 -%}
	{%- assign sidebar_recent_posts_exclude = sidebar_recent_posts_exclude | concat: sidebar_related_content -%}
{%- endif -%}
<aside class="blog-sidebar d-flex flex-column gap-4">
	{%- if show_sidebar_search %}{% include "/partials/blog_sidebar/_searchform.liquid" %}{% endif -%}
	{%- comment %}CTA early so mobile visitors see Visit Us before scrolling past the full post grid{% endcomment -%}
	{%- include "/partials/blog_sidebar/_simple_cta.liquid" -%}
	{%- include "/partials/blog_sidebar/_topics.liquid" -%}
	{%- include "/partials/blog_sidebar/_contextcard.liquid" -%}
	{%- include "/partials/blog_sidebar/_relatedcontent.liquid" -%}
	{%- include "/partials/blog_sidebar/_recentposts.liquid" -%}
</aside>