Skip to content

Instantly share code, notes, and snippets.

@mpmont
Created March 19, 2013 12:21
Show Gist options
  • Save mpmont/5195644 to your computer and use it in GitHub Desktop.
Save mpmont/5195644 to your computer and use it in GitHub Desktop.
<?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', 'article');
$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->article->Get( array('status' => 'active') );
header("Content-Type: application/rss+xml"); // important!
$this->load->view('common/rss', $data);
}
}
<xml version="1.0" encoding="utf-8">
<rss version="2.0">
<channel>
<title>{{ $feed_name }}</title>
<link>{{ $feed_url }}</link>
<description>{{ $page_description }}</description>
<lastBuildDate>{{ date('D') }}, {{ date('d') }} {{ date('M') }} {{ date('Y') }} {{ date('G') }}: {{ date('i') }}:{{date('s')}} {{date('e') }}</lastBuildDate>
<language>{{ $page_language }}</language>
@foreach ($posts as $post)
<item>
<title>{{ $post->title }}</title>
<link>{{ site_url('section/article/'. $post->id) }}</link>
<guid>{{ site_url('section/article/'. $post->idarticle) }}</guid>
<pubDate>{{ $post->articledate }} </pubDate>
<description>[CDATA[ {{ character_limiter(strip_tags($post->intro, 200)) }} ]]</description>
</item>
@endforeach
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment