Last active
August 29, 2015 14:01
-
-
Save mrailton/c67cf00eca48108a60b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once("includes/init.php"); | |
// instantiate blog class | |
$blog = new Blog($db); | |
$posts = $blog->get_posts(); | |
$lastpostdate = $blog->last_post_date(); | |
header("Content-Type: application/xml; charset=UTF-8"); | |
echo '<?xml version="1.0" encoding="UTF-8" ?>' . | |
'<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">'. | |
'<channel>' . | |
'<title>'.SITE_NAME.'</title>' . | |
'<atom:link href="http://'.SITE_URL.'/feed/" rel="self" type="application/rss+xml"/>' . | |
'<link>http://'.SITE_URL.'</link>' . | |
'<description>'.SITE_NAME.'</description>' . | |
'<lastBuildDate>'. date("D, d M Y H:i:s O", strtotime($lastpostdate['date'])) .'</lastBuildDate>' . | |
'<sy:updatePeriod>hourly</sy:updatePeriod>' . | |
'<sy:updateFrequency>1</sy:updateFrequency>' . | |
'<language>en-GB</language>'; | |
foreach ($posts as $post) { | |
echo '<item>'; | |
echo '<title>'. $post['title'] .'</title>'; | |
echo '<link>http://'.SITE_URL.'/'. $post['slug'] .'</link>'; | |
echo '<pubDate>'.date("D, d M Y H:i:s O", strtotime($post['date'])).'</pubDate>'; | |
echo '</item>'; | |
} | |
echo '</channel>'. | |
'</rss>'; |
What is the init.php
? Btw, it's cool and simple. Thanks.
init.php calls the config to pull the constants as well as running the autoloader for the blog class.
Thanks for your comments, for some reason I didn't get an alert about it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code creates an RSS feed from a custom blog.
$blog->get_posts() returns the results of "SELECT * FROM blog_posts"
$blog->last_post_date returns the result of 'SELECT * from blog_posts ORDER BY id DESC LIMIT 1'
The resultant RSS feed validates as a valid RSS 2.0 feed.