Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
它可能不起作用的原因是
$feed->items
可能不是数组(基于fetch_rss
调用)。要检查某物是否是数组,您可以执行以下操作:
is_array($feed->items);
// returns true or false如果它是数组,您可以调用
array_slice( )
然而,更好的解决方案是检查
$feed
变量,以确保它在处理之前返回您要查找的内容。The reason it may not work is because
$feed->items
may not be an array(based on thefetch_rss
call).To check if something is an array, you can do:
is_array($feed->items);
// returns true or falseIf it is an array, you can then call
array_slice()
The better solution however, is to check the
$feed
variable to make sure it returned what you are looking for before processing.看起来
$feed->items
可能是也可能不是数组。这一切都取决于$feed
的分配方式,这取决于fetch_rss
内部发生的情况,尽管这对您的问题有些倾斜,但似乎您有一些多余的代码。您执行切片以单独获取数组的第一个元素,然后仅使用该一个元素迭代列表?相反,您可以简单地对第一个元素执行您喜欢的任何操作。
Looks like
$feed->items
may or may not be an array. That all depends on how$feed
gets assigned, which depends on whats happening insidefetch_rss
Although tis somewhat oblique to your problem, it appears you have some superfluous code. You do the slice to get the first element the array alone, and then you iterate on a list with just that one element? Instead you can simply perform whatever you like on that first element.
我在使用与我正在使用的主题相关的 RSS 提要时也遇到过同样的问题。在管理方面,代码应该显示同一艺术家的更多主题,但是我收到相同的 array_slice 错误,因为 $feed->items 为空。
RSS 源的链接工作正常,并且该地址有信息。于是,我开始环顾四周,发现问题出在RSS上,而不是代码上(好吧,原来的问题。显示该错误仍然是一个问题)。我将 fetch_rss() 命令指向不同的提要,它工作得很好。
在艺术家调整他的提要以适应该命令之前,我个人无能为力。但是,如果您无法将此命令与您自己的提要一起使用,请尝试确保提要采用此 Wordpress 命令所需的格式。
很抱歉在一个老问题上发帖,但网络上的其他地方没有直接的答案。
I've had this same problem with an RSS feed related to a theme I'm using. On the admin side, the code is supposed to display more themes by the same artist, however I'm getting the same array_slice error, because $feed->items is null.
The link to the RSS feed is working properly, and there is information at the address. So, I started looking around, and I found that the problem is with the RSS, not the code (well, the original problem. It's still a problem that that error is displayed). I pointed the
fetch_rss()
command at a different feed, and it works fine.Until the artist adjusts his feed to work with the command, there's nothing I can personally do. But if you're having trouble getting this command to work with your own feeds, try making sure the feeds are in the required format for this Wordpress command.
Sorry to post on an old question, but there are no direct answers elsewhere on the web.