Statamic Collections and Entries Setup
Collections are the main organizational unit of content in Statamic. Analogous to Post Types in WordPress, but more flexible: defines URL structure, sort order, tree structure, and Blueprint for each content type.
Creating a Collection
php artisan statamic:make:collection blog
php artisan statamic:make:collection pages --structure
Collection config:
# content/collections/blog.yaml
title: Blog
template: blog/show
layout: layout
date: true
date_behavior:
past: public
future: private # hide scheduled posts
sort_field: date
sort_direction: desc
paginate: 12
slugs: true
propagate: false
routes: '/blog/{slug}'
Structured Collections (pages)
# content/collections/pages.yaml
title: Pages
template: page
layout: layout
routes: '/{parent_uri}/{slug}'
structure:
root: true # root pages without parent
max_depth: 3
expects_root: true
Entry (Record) in File System
# content/collections/blog/2024-03-15.my-first-post.md
---
id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
title: My First Post
slug: my-first-post
date: 2024-03-15
template: blog/show
blueprint: post
published: true
categories:
- key: web-development
featured_image: assets/images/hero.jpg
excerpt: Short description of the post
---
Content of the post in Markdown.
Querying Entries in Templates
{{# Basic query #}}
{{ collection:blog }}
{{ title }} — {{ date format="d.m.Y" }}
{{ /collection:blog }}
{{# With filtering and sorting #}}
{{ collection:blog
status:is="published"
sort="date:desc"
limit="6"
taxonomy:categories="web-development"
}}
{{ results }}
{{ partial:blog/post-card :post="this" }}
{{ /results }}
{{ /collection:blog }}
{{# Filter by custom field #}}
{{ collection:events
where:event_date:gte="{ now }"
sort="event_date:asc"
limit="10"
}}
{{# Across multiple collections #}}
{{ collection from="blog|news|press-releases"
sort="date:desc"
limit="10"
}}
PHP Queries via API
use Statamic\Facades\Entry;
use Statamic\Facades\Collection;
// Get entries
$posts = Entry::query()
->where('collection', 'blog')
->where('status', 'published')
->orderBy('date', 'desc')
->limit(10)
->get();
// Single entry by slug
$post = Entry::query()
->where('collection', 'blog')
->where('slug', $slug)
->first();
// Entry by ID
$entry = Entry::find('a1b2c3d4-e5f6-7890');
Taxonomies: Categories and Tags
# content/taxonomies/categories.yaml
title: Categories
route: '/blog/category/{slug}'
collection:
- blog
- news
{{# List all categories with count #}}
{{ taxonomy:categories sort="title:asc" }}
<a href="{{ url }}">{{ title }} ({{ entries_count }})</a>
{{ /taxonomy:categories }}
Setting up 3–5 collections with proper routes and taxonomies — 4–8 hours.







