Add Blog Category
Learn how to add custom categories to organize your blog posts
Learn how to add custom categories to organize your blog posts in Plainform.
Goal
By the end of this recipe, you'll have added custom categories to your blog that readers can use to filter posts.
Prerequisites
- A working Plainform installation
- Basic understanding of JSON syntax
Steps
Open the Locale File
Navigate to locales/en.json and find the blogPage.categories section:
{
"blogPage": {
"categories": [
{
"title": "All",
"id": 1
},
{
"title": "Category 1",
"queryParam": "category-1",
"id": 2
},
{
"title": "Category 2",
"queryParam": "category-2",
"id": 3
},
{
"title": "Category 3",
"queryParam": "category-3",
"id": 4
}
]
}
}The "All" category is required and shows all posts. Don't remove it!
Add Your Categories
Replace the placeholder categories with your own:
{
"blogPage": {
"categories": [
{
"title": "All",
"id": 1
},
{
"title": "Tutorial",
"queryParam": "tutorial",
"id": 2
},
{
"title": "Product Updates",
"queryParam": "product-updates",
"id": 3
},
{
"title": "Engineering",
"queryParam": "engineering",
"id": 4
},
{
"title": "Company",
"queryParam": "company",
"id": 5
}
]
}
}Field explanations:
title- Display name shown in the UI for filter buttons and post category badges (e.g., "Tutorial", "Product Updates")queryParam- URL parameter for filtering (e.g.,/blog?category=tutorial). Use lowercase values; if the display name has spaces, replace them with hyphens.id- Unique identifier (increment for each category)
Important: The queryParam should be lowercase with hyphens, matching how you'll use it in blog post frontmatter. The UI displays the title, so use product-updates for the query value and "Product Updates" for the visible label.
Save and Preview
Save the file and refresh your blog page at http://localhost:3000/blog to see your new categories.
The category filter buttons will appear at the top of your blog page.
Using Categories in Blog Posts
When creating a blog post, use the exact queryParam value in the frontmatter:
---
title: My Tutorial Post
publishedAt: 2024-01-15
summary: Learn how to do something awesome
author: john-doe
category: tutorial
img: https://your-bucket-name.s3.region.amazonaws.com/image.jpg
---
Your content here...The category field in your blog post frontmatter must match the queryParam value exactly (case-sensitive). Use lowercase and hyphens instead of spaces. The blog UI will display the matching category title.
Category Naming Best Practices
Good category names:
- Tutorial
- Product Updates
- Engineering
- Company News
- Case Studies
- How-To Guides
Avoid:
- Too many categories (5-7 is ideal)
- Overlapping categories (e.g., "Tutorials" and "How-To Guides")
- Vague names (e.g., "Miscellaneous", "Other")
Verification
After adding categories:
- Visit
/blogto see the category filter buttons - Click each category to verify filtering works
- Create a test post with a category to confirm it appears in the correct filter
- Check that the "All" category shows all posts
Common Issues
Category Filter Not Working
Issue: Clicking a category doesn't filter posts
Solution:
- Verify the
queryParaminlocales/en.jsonmatches thecategoryin your blog post frontmatter exactly - Check for typos, case mismatches, or spaces that should be hyphens
- Ensure the blog post has a valid
categoryfield
Category Not Appearing
Issue: New category doesn't show up on the blog page
Solution:
- Check JSON syntax is valid (no trailing commas, proper quotes)
- Verify you saved the
locales/en.jsonfile - Restart the dev server if hot reload didn't pick up changes
- Clear browser cache
Posts Not Filtering Correctly
Issue: Posts appear in wrong categories
Solution:
- Ensure each blog post's
categoryfield matches aqueryParamexactly - Check for extra spaces or special characters; multi-word category values should use hyphens
- Verify the category exists in
locales/en.json
Next Steps
- Add Blog Post - Create posts with categories
- Add Blog Author - Add author profiles
- Locales & Site Config - Learn about locale management
How is this guide ?
Last updated on