我在同一页面的两个位置使用此脚本来输出一些RSS提要:
<?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(3);
$rss_items = $rss->get_items(0, $maxitems);
?>
<?php if ($maxitems == 0) echo \'<p class="alert">No activity to display.</p>\'; ?>
<ul>
<?php
if (!$maxitems == 0)
foreach ( $rss_items as $item ) : ?>
<li>
<a href="<?php echo $item->get_permalink(); ?>">
<?php echo $item->get_title(); ?>
<time datetime="<?php echo $item->get_local_date(\'%Y-%m-%d %H:%M\'); ?>" class="timestamp">
<?php echo $item->get_local_date(\'%A %d %b %H:%M\'); ?>
</time>
</a>
</li>
<?php endforeach; ?>
</ul>
我正在手动设置
functions.php
至两小时:
function filter_handler( $seconds ) {
return 7200;
}
add_filter( \'wp_feed_cache_transient_lifetime\', \'filter_handler\' );
每天有几次,提要会中断并显示此错误:
Fatal error: Call to undefined method WP_Error::get_item_quantity() in /public_html/wp-content/themes/twentyeleven/home-page.php on line 100
WordPress获取这个推特提要似乎偶尔会失败,然后错误会输出2个小时,直到刷新缓存。
我怎么才能避开这个?