Learn to build a lean & flexible blogging platform
Creating an RSS Feed
Although not as important as it used to be in the past, an RSS feed is still a standard part of most blogs. Kirby doesn’t come with RSS capabilities by default, but it can easily be added. This also allows us to explore “plugins” in Kirby.
Inside of the “site” directory, you might have already spotted that empty “plugin” subfolder. Well, its empty days are over! Before we start hacking our own RSS feed plugin, however, let’s see if someone else hasn’t already done this for us: welcome to the Kirby plugin directory.
Installation is as simple as throwing those “feed.php” and “template.php” files into a new “feed” subfolder in “plugins”.
The “template.php” file determines how our RSS feed will be rendered. In most projects, there will be no need to change anything. However, if you wanted to, making changes is quite straightforward: this template works much like the ones we worked with earlier.
To make an example, if your posts had an additional “Subtitle” data field, you could simply modify the <title> node as follows:
In case you want to get a feel for the inner workings of the plugin, you can also have a look at “feed.php”. However, understanding and creating Kirby plugins (although fairly simple) is beyond the scope of this course.
A Page for Our RSS Feed
At the moment, the RSS feed plugin isn’t used anywhere in our project, yet. We need to create both a page item and a template to change this.
Creating the page is very easy: in the “content” directory, we create a “feed” folder with an empty “feed.txt” file.
Currently, Kirby can’t find a template for a “feed.txt” page. Therefore, it uses the “default.php” template - which is clearly not what we want.
Let’s create a custom “feed.php” file in site/templates/. The plugin’s GitHub page already proposes a very sensible default template:
'title' => 'Latest articles',
'description' => 'Read the latest news about our company',
'link' => 'blog'
The configuration is rather simple:
The plugin starts with the “blog” page (which we’ll have to change to “posts” in a minute)…
and collects all visible (i.e. numbered) child pages herein…
changes their sorting order (so that newest posts are first)…
and supplies just the latest 10 items to the “feed” method (which was added by our plugin).
Let’s quickly replace “blog” with “posts” so that the page function has the correct folder to look for our post items. You can delete the ‘link’ parameter since we want our main feed to point at our homepage (which is the plugin’s default).