简体   繁体   English

Simplepie get_permalink返回供稿链接,而不是项目链接

[英]Simplepie get_permalink returns feed link instead of item link

I am using Simplepie to access this feed . 我正在使用Simplepie访问此提要 I use SimplePie's get_permalink() method to get the link of each item in the feed. 我使用SimplePie的get_permalink()方法获取供稿中每个项目的链接。 This works with other feeds, but with this one get_permalink() is returning the URL of the feed as a whole, rather than the URL of a particular item. 这可与其他提要一起使用,但get_permalink()返回整个提要的URL,而不是返回特定项目的URL。

Code: 码:

$feed = new Rss_lib();
$feed->set_feed_url($feed_array);
$success = $feed->init();
$feed->handle_content_type();

foreach($feed->get_items() as $item)
{
   $item_arr = array(
       'permalink'   => $item->get_permalink(),
       'title'       => $item->get_title(),
       'description' => $item->get_description(),
       'date'        => $item->get_date()
   );
   $return[] = $item_arr;
}

I want to receive the permalink of the item rather than the feed's URL. 我想接收项目的永久链接,而不是Feed的URL。

It looks like SimplePie has a bug with regards to this feed. 看来SimplePie与此供稿有关的错误。 To get the link for the item you just need to retrieve all links and then pick out the one you want. 要获得该项目的链接,您只需要检索所有链接,然后挑选您想要的链接。 For the feed in your question the second link is the link you are after (using my version of SimplePie anyway, different versions might parse it differently). 对于您问题中的提要,第二个链接是您要访问的链接(无论如何,使用我的SimplePie版本,不同版本的解析可能会有所不同)。

$links = $item->get_links();
$link = $links[1];

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

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