Generating RSS feed

Posted on April 30, 2020

On this article we dicuss how to generate a rss feed outpur for the blog posts. We are going to make a simple output with the most basic information for the feed. This is the view file (core/views/rss.php)

header('Content-Type: application/rss+xml; charset=utf-8');
echo '<?xml version="1.0" encoding="utf-8"?>';
<rss version="2.0" xmlns:atom="">
<atom:link href="<?=gila::config('base')?>rss" rel="self" type="application/rss+xml" />
<?php foreach($items as $item) { ?>
<?php } ?>
  • The date('r') is used to output the date in this format: Sun, 23 Jul 2017 06:14:51 GMT
  • permite us print html tags in description


Since its is a blog feed the controller to be used will be the blog class. We create the action feed:

    function feedAction()
        include 'src/core/views/rss.php';

 The information is taken simply from the configuration variables. The function latestposts() returns a prefixed number of the latest published posts, in the form of generator of objects.

That's all it is, the path /blog/feed will return the rss feed. 

The feed of this website (more attributes have been added in the feed):