2012-10-28 42 views
0

我努力让set_item_limit工作。 Feed正常,但只是呈现每个帖子。下面是我使用的代码:简单的馅饼“set_item_limit”不是

// 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(); 

而这里的HTMLy位:

<?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; ?> 

表不是问题!

任何想法?

回答

4

的问题是

$feed->set_item_limit(5); 

是对合并饲料和不会为单一的饲料....你需要

变化

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

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

这会将其限制为5个ems

SimplePIE Get_ITEMS