0

I'm struggling to get set_item_limit to work. The feed comes in fine, but just renders every post. Here's the code I'm using:

// Make sure SimplePie is included. You may need to change this to match the location of autoloader.php
// For 1.0-1.2:
#require_once('../simplepie.inc');
// For 1.3+:
require_once('php/autoloader.php'); 
// process this feed with all of the default options.
$feed = new SimplePie(); 
// Set which feed to process.   http://simplepie.org/blog/feed/
$feed->set_feed_url('https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=Tweet_Yourself'); 
// Run SimplePie.
$feed->set_item_limit(5);
$feed->init(); 
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();

And here's the HTMLy bit:

<?php
//loop through all of the items in the feed, and $item represents the current item in the loop.
foreach ($feed->get_items() as $item): ?>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100" align="left"><img src="sitewise/Tweet_Yourself_avatar.gif" alt="TweetYourself Twitter Feed" /></td>
        <td>
            <div class="item">
                <h3><i><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></i></h3>
                <?php echo $item->get_description(); ?>
                <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
                <hr />
            </div>
        </td>
      </tr>
    </table>

<?php endforeach; ?>

The table isn't the issue!

Any ideas?

1 Answers1

5

The issue is

$feed->set_item_limit(5);

Is for merging feeds and not for a single feed.... you need to

change

foreach ($feed->get_items() as $item): ?>

to

foreach ($feed->get_items(0, 5) as $item): ?>

This would limit it to 5 items

SimplePIE Get_ITEMS

Caiapfas
  • 146
  • 1
  • 2
  • 10