Skip to content

Statamic SSG: Include category taxonomy archive page

October 9th, 2023 Statamic A bookcase with colorful books in it

When working with Statamic's static site generation (SSG), one of the challenges you might encounter is generating static pages for category taxonomies. By default, Statamic generates static pages for entries but may not create static pages for categories. In this short note, I'll share how I overcame this hurdle by adding a URL to the ssg.php configuration file, allowing me to generate a static archive page containing all category taxonomy terms.

The Challenge: A Category archive page in Statamic SSG

In Statamic, category taxonomies are a powerful way to organize and categorize your content. However, when you embark on static site generation, you might notice that static pages are generated only for your entries. The category taxonomy archive page, which play a crucial role in structuring your content, is left out.

The Solution: Adding an URL to ssg.php

The solution to generating static pages for category taxonomies is surprisingly straightforward. You can achieve this by adding a URL to the ssg.php configuration file in your Statamic project. Here's how to do it:

1. Locate Your ssg.php Configuration File
In your Statamic project, navigate to the config directory. Inside this directory, you'll find the ssg.php configuration file. Open it in your preferred code editor.

2. Configure the URL for Category Taxonomies
To generate static pages for category taxonomies, you'll need to add a URL pattern that corresponds to your taxonomy structure. In the ssg.php file, look for the urls section.

'urls' => [
'/feed',
'/feed/atom',
'/categories'
],
php

In this example, we've added a URL pattern /categories that maps to the category archive page in my blog.

3. Create the needed templates for the archive page and terms
We need to tell Statamic which template to use for the category archive, and the terms. To do this, in your views directory, create a categories directory. Within that directory create two files:

  • index.antlers.html which will be used for the category archive page,

  • show.antlers.html which will be used to show content associated with the selected term.

4. Regenerate your static site
After making these configurations, it's time to regenerate your static site. Open your terminal and run the Statamic CLI command:

php please ssg:generate
bash

That's it!

Statamic will now generate a static page for your category taxonomy archive according to the URL pattern you've defined, making your static site even more comprehensive and structured.

About Marcel Bootsman

Marcel discovered the web in 1995. Since then he has paid attention to and worked with lots of technologies and founded his own WordPress oriented business nostromo.nl in 2009.

Currently Marcel is Business Development Manager Dutch & DACH Markets at Kinsta where he helps Kinsta's client base grow with Managed WordPress, Application, Database and Static site hosting.

You can contact Marcel on a diverse range of online platforms. Please see the Connect section on the homepage for the details.