简体   繁体   English

WordPress RSS Feed在PHP文件中不起作用

[英]WordPress RSS Feed is not functions in a PHP file

I am using a plugin called WP- RSS feed. 我正在使用一个名为WP- RSS feed的插件。 As it so happens, acording to their website you can use an RSS feed directly inside of your PHP template. 碰巧的是,根据他们的网站,您可以直接在PHP模板内部使用RSS feed。 When I place the following code into the template, it does not fire but instead I get an error that says, "Warning: strpos() expects parameter 1 to be string, array given in /nas/wp/www/staging/sfhr/wp-includes/SimplePie/Content/Type/Sniffer.php on line 97" 当我将以下代码放到模板中时,它不会触发,但是我收到一条错误消息:“警告:strpos()期望参数1为字符串,在/ nas / wp / www / staging / sfhr /中给出的数组第97行上的wp-includes / SimplePie / Content / Type / Sniffer.php”

<?php echo do_shortcode(RSSImport(5,"http://www.indystar.com/apps/pbcs.dll/section?Category=SPORTS0107&template=rss"));
 ?> 

The code for line 97 is the following: 第97行的代码如下:

if (($pos = strpos($this->file->headers['content-type'], ';')) !== false)
        {
            $official = substr($this->file->headers['content-type'], 0, $pos);
        }
        else
        {
            $official = $this->file->headers['content-type'];
        }

Any ideas why I get these erros? 有什么想法为什么我会犯这些错误吗?

If you are using the plugin RSS-Import 如果您使用的是RSS-Import插件

http://wordpress.org/extend/plugins/rss-import/ http://wordpress.org/extend/plugins/rss-import/

then according to the documentation, you can add this into your template files: 然后根据文档,可以将其添加到模板文件中:

<?php RSSImport(10, 'http://bueltge.de/feed/'); ?>

If you want to use do_shortcode() then you could try this: 如果要使用do_shortcode()则可以尝试以下操作:

<?php 
  echo do_shortcode('[RSSImport display="5" feedurl="http://bueltge.de/feed/"]');
?>

You can also fetch RSS feeds without plugins with the Wordpress function fetch_feed() : 您还可以使用Wordpress函数fetch_feed()获取不带插件的RSS feed:

<?php $feed = fetch_feed( $uri ); ?>

This function is using the SimplePie package and caches the feeds automatically. 此函数正在使用SimplePie包,并自动缓存提要。 You can read more about it here in the Codex: 您可以在法典中阅读有关此内容的更多信息:

http://codex.wordpress.org/Function_Reference/fetch_feed http://codex.wordpress.org/Function_Reference/fetch_feed

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM