我正在尝试从推特帐户获取一些最新的帖子,没有插件。根据Botcrawl.com\'s 教程,这应该足够了:
<ul>
<?php
include_once(ABSPATH . WPINC . \'/feed.php\');
$rss = fetch_feed(\'https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=BarackObama\');
$maxitems = $rss->get_item_quantity(4);
$rss_items = $rss->get_items(0, $maxitems);
?>
<ul>
<?php if ($maxitems == 0) echo \'<li>No items.</li>\';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<li>
<a href=\'<?php echo $item->get_permalink(); ?>\'>
<?php echo $item->get_title(); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
但是,我得到以下错误:
Fatal error: Call to undefined method WP_Error::get_item_quantity() in /Users/username/Desktop/journal_wp/wp-content/themes/Journal_theme/index.php on line 155
有没有人有过这样的经验,并且知道为什么这是一个致命的错误?