Skip to content

Instantly share code, notes, and snippets.

@mpmont
Created January 26, 2012 16:14
Show Gist options
  • Save mpmont/1683554 to your computer and use it in GitHub Desktop.
Save mpmont/1683554 to your computer and use it in GitHub Desktop.
Rss
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Feed extends CI_Controller {
function __construct() {
parent::__construct();
// load dependencies
$this->load->model('admin/articles_model');
$this->load->helper('xml');
$this->load->helper('text');
}
public function index( ){
$data['feed_name'] = 'MyWebsite.com';
$data['encoding'] = 'utf-8';
$data['feed_url'] = base_url().'common/feed';
$data['page_description'] = 'What my site is about comes here';
$data['page_language'] = 'pt-pt';
$data['creator_email'] = '[email protected]';
$data['posts'] = $this->articles_model->GetArticles(
array(
'articlestatus' => 'active')
);
header("Content-Type: application/rss+xml"); // important!
$this->load->view('common/rss', $data);
}
}
<?php echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version="2.0">
<channel>
<title><?php echo $feed_name; ?></title>
<link><?php echo $feed_url; ?></link>
<description><?php echo $page_description; ?></description>
<lastBuildDate><?=date('D');?>, <?=date('d');?> <?=date('M');?> <?=date('Y');?> <?=date('G');?>:<?=date('i');?>:<?=date('s');?> <?=date('e');?></lastBuildDate>
<language><?php echo $page_language; ?></language>
<?php foreach ($posts as $post): ?>
<item>
<title><?=$post->articletitle; ?></title>
<link><?=site_url('section/article/'. $post->idarticle);?></link>
<guid><?=site_url('section/article/'. $post->idarticle);?></guid>
<pubDate><?=$post->articledate; ?></pubDate>
<description>[CDATA[ <?php echo character_limiter(strip_tags($post->articleintro, 200));?> ]]</description>
</item>
<?php endforeach; ?>
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment