Custom post types with Kirby CMS

I was recently asked on Twitter, how I implemented custom post types on this blog. Since Bastian already has a great post explaining all the nitty gritty details, I’ll just give a basic overview of what I did:

Customise the blog loop

Your blog loop (often in a file called blog.php or similar) controls what posts are displayed on your blog’s homepage. Typically it’ll contain a foreach-loop that iterates through a set number of latest posts and displays the header and text or text-extract for each post.

In order to display each type of post differently, my blog.php checks the type of template used by each post. With Kirby, that’s easy to do – this bit of code checks if an article is a video post:

if ($article->template() == 'article.video'):
?>

Add separate if’s for each type of post you want to have.

Customizing post styles

You’ll need separate post templates in your Kirby templates folder. Once one of those posts is found (e.g. “article.video.txt”), the custom code is called and my blog includes a custom font-awesome icon in the header.

You can customize each type of post as little or as much as you like – my ‘articles’ (“proper” blog entries such as this one) have a more elaborate paper card design with tucked corners to make them stand out:

tucked-corners

Make it responsive

When playing around with custom post designs, don’t forget to make sure it looks alright on a mobile device as well. I currently only show the fancy card design to desktop users – it added too much visual clutter on smartphone screens.

That’s it! If you have any additional questions, comments or links to your own Kirbified custom post types, get in touch on Twitter!