我将 php rss 解析库simplepie 加载到我的网站上,并将其包含在 header.php 文件中,如下所示:
<?php
// Make sure that SimplePie is loaded
require_once('inc/simplepie.inc');
$feed = new SimplePie('rss.com'); <-- This is a example url
// Make sure the content is being served out to the browser properly.
$feed->handle_content_type();
?>
然后我尝试从另一个名为 page.php 的页面访问该对象,它给了我这个错误:
Fatal error: Call to a member function get_items() on a non-object in /home/callofdu/public_html/wp-content/themes/Starkers/page.php on line 13
我从这行代码中得到错误:
<?php
foreach ($feed->get_items() as $item)
{}
?>
这很奇怪,因为如果我将这两个代码块一起包含在同一个 php 页面上,它就一切正常。
我只是不明白一些事情,请帮助。