With this tutorial, you will learn how to create a RSS feed for your blog. To see an example of a RSS feed, visit https://www.danielpinero.com/feed. To create your own feed, write a PHP file following these steps:
Make a query to your blog's MySQL database, and add title, metadescription and URL of each post to a string ($feed), in this way:
$result = mysql_query("SELECT `title`, `description`, `url` FROM `blog`
ORDER BY `date` DESC;");
while($row = mysql_fetch_array($result)){
$feed.= "<item><title>".$row['title']."</title>
<description>".$row['description']."</description>
<link>http://www.tublog.com/".$row['url']."/</link>
</item>";
}
Next, nest the string $feed under the general description of your blog:
$feed = "<?xml version='1.0'?>
<rss version='2.0'>
<channel>
<title>Your blog's title</title>
<description>Your blog's description</description>
<link>http://yourblogaddress.com</link>" . $feed . "</channel></rss>";
This last line will definitely create the RSS file as "feed" (with no extension).
file_put_contents("feed", $feed);
Save the PHP file and run it. Your first RSS feed will be created with all the posts from your blog. As well, you can run this PHP file through a cron job so it runs automatically in a predetermined frequency.
It's very important that you validate the RSS feed so that applications like Feedly can effectively recognize it. For this, use the W3C Feed Validation Service.