0

我正在努力让 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

1 回答 1

5

问题是

$feed->set_item_limit(5);

用于合并提要而不是单个提要....您需要

改变

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

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

这会将其限制为 5 个项目

SimplePIE Get_ITEMS

于 2012-11-09T03:02:47.460 回答