Did you know that you can easily send me feedback, by hitting 'Send feedback' in the footer? Anyway, I received feedback for the first time a couple of hours ago. It simply stated:
Your blog seems to be lacking a RSS feed.
I enjoy to learn new things, and improve my website further. So I immediately implemented a RSS Feed. 🤓 You can now subscribe to it, and be updated of new articles: https://tonnygaric.com/blog/feed
If you are curious how I implemented it, read further. Note that I use Kirby as CMS, so the information below only applies for Kirby-flavoured websites.
How to add a RSS feed to your Kirby website
1) Add an invisible feed page
We want our feed to be available at
https://tonnygaric.com/blog/feed, but we do not want it to appear in any menu, or sitemap. So we will keep it invisible.
Note: If a page is visible, Kirby prefixes the folder name with a number. Thus by not adding a number, the page will be invisible, but accessible.
We create a folder called
feed folder, we create a file called
blogfeed.txt we can add some basic information, for example:
Title: Tonny Garić's Blog \---- Description: The latest updates from Tonny Garić's blog \----
Note: I had to escape the
----, you must not include the
\ from the above example.
2) Download and add the feed plugin
Download the feed plugin from GitHub. It is a simple wrapper to make the feed generation easier.
We create a folder called
site/plugins/, and place the files of the feed plugin inside
3) Create a template
feed/blog folder, we created
site/templates we will now create a file named
blogfeed.php. By providing this template we make sure that this template will be used instead of the
default.php template when we open
We now need to get the right set of items for our feed, by placing the following in
<?php // Find blog page, fetch all visible children (articles), flip them to get the // latest first, limit it to the 10 last articles and call the feed method. // The feed method is being created by the feed plugin. echo page('blog')->children()->visible()->flip()->limit(10)->feed(array( 'title' => $page->title(), 'description' => $page->description(), 'link' => 'blog', )); ?>
4) Link our feed
We can now visit our feed at
https://tonnygaric.com/blog/feed. Now, we can add links to it:
<a href="<?= url('blog/feed') ?>"> Subscribe to our RSS feed </a>
We can also add the feed to the header of our website—so browsers and feed readers can automatically detect it.
<link rel="alternate" type="application/rss+xml" href="<?= url('blog/feed') ?>" title="<?= html($pages->find('blog/feed')->title()) ?>"/>
That is it! We are done. ✅
Also see Kirbys cookbook about RSS-Feeds.
I do not know who send me the feedback, but thank you. I appreciate it.