1

Limit feeds on simplepie using cakephp 1.2.x

Posted November 12th, 2008 in PHP, Programming, Projects and tagged , , , , , , , by Louie Miranda

I am currently working on Simplepie and CakePHP 1.2.x. I have a working code that successfully display xml feeds from different remote sources, a sample can be viewed on my homepage. And, I can’t find how to limit it.

My problem on limiting the rss/xml feeds is extending simplepie up to the view/ of cakephp. At first, I thought I should just do.

$feed->set_item_limit(5);

But, looking closely on the documentation:
http://simplepie.org/wiki/reference/simplepie/set_item_limit#limit

I shouldn’t be doing that. And, I should be working on get_items() instead.
http://simplepie.org/wiki/reference/simplepie/get_items

get_items(0, 5) as $item): ?>
<div class="item">
<h2 class="title"><a href="&lt;?php echo $item-&gt;get_permalink(); ?&gt;">get_title(); ?&gt;</a></h2>
get_description(); ?&gt;
 
<small>Posted on get_date('j F Y | g:i a'); ?&gt;</small></div>

Hmm.. I am going to find the solution on this problem.

One Response so far.

  1. Santi says:

    Hi!!

    I did it using your second option, here is my code:

    $cannabisymas = new SimplePie(‘http://www.cannabisymas.com/blog/?feed=rss2‘);
    $cannabisymas->handle_content_type();

    foreach ($cannabisymas->get_items(0, 10) as $item)
    {
    $feed = $item->get_feed();

    echo ”;
    echo ‘get_permalink() . ‘” target=”_blank”>’ . $item->get_title() . ‘‘;
    echo ” . $item->get_date() . ”;
    echo ”;
    }

Leave a Reply