Basker Docs

Category template

Render the blog-scoped archive for one post category

templates/category.liquid renders the published posts in one category. This is a dedicated classic-theme route; Website Builder sites handle the route separately.

Route

/blogs/:blogSlug/categories/:slug

For example, /blogs/news/categories/reviews renders templates/category.liquid. The route does not select named template variants.

Context

The template receives category, posts, and the normal template globals.

category

PropertyTypeDescription
idstringCategory ID
titlestringCategory name
slugstringCategory slug
imagemediaCategory image, when configured
blogstringRelated blog ID

posts

The route returns at most 100 published posts. Each entry is a route-specific summary with id, title, slug, description, image, publishDate, and categories. It does not include the full post template context.

Example

Remove the active language prefix before reading the blog slug from request.path; this keeps generated links correct on translated routes.

{% layout 'layouts/default.liquid' %}

{% capture content_for_layout %}
  {% assign route_path = request.path | remove_first: locale_prefix %}
  {% assign route_parts = route_path | split: '/' %}
  {% assign blog_slug = route_parts[2] %}

  <main class="category-page">
    <header>
      <h1>{{ category.title }}</h1>
      <p>{{ posts.size }} {% if posts.size == 1 %}post{% else %}posts{% endif %}</p>
    </header>

    {% if posts.size > 0 %}
      <ul class="post-list">
        {% for post in posts %}
          <li>
            <article>
              {% if post.image %}
                <img
                  src="{{ post.image | image_url: width: 480, height: 300, fit: 'cover' }}"
                  alt="{{ post.image.alt | default: post.title }}"
                  loading="lazy"
                >
              {% endif %}
              <h2>
                <a href="{{ locale_prefix }}/blogs/{{ blog_slug }}/posts/{{ post.slug }}">
                  {{ post.title }}
                </a>
              </h2>
              {% if post.publishDate %}
                <time datetime="{{ post.publishDate }}">{{ post.publishDate | date: '%d %B %Y' }}</time>
              {% endif %}
              {% if post.description %}<p>{{ post.description }}</p>{% endif %}
            </article>
          </li>
        {% endfor %}
      </ul>
    {% else %}
      <p>No posts in this category yet.</p>
    {% endif %}
  </main>
{% endcapture %}

{% schema %}
{
  "settings": []
}
{% endschema %}

Post relationships include category records and the related blog. Use those slugs rather than handleize:

{% for category in post.categories %}
  <a href="{{ locale_prefix }}/blogs/{{ post.blog.slug }}/categories/{{ category.slug }}">
    {{ category.title }}
  </a>
{% endfor %}

On this page