Domanda

How do I get the current item's feed url or the feed url's position in the feeds array while looping through get_items?

something like this:

foreach ($simplePie->get_items(0,100) as $item) {
   $rss_url = $item->get_rss_feed();
   $position = $item->get_rss_feed_position();
}

UPDATE: please not what the following code echos, http://blog.apsltd.com/ 3 times.

$simplePie = new SimplePie();
$simplePie-> set_feed_url('http://blog.apsltd.com/feeds/posts/default?alt=rss');
$simplePie->init();

foreach ($simplePie-> get_items(0, 1) as $item) {
    $feed = $item->get_feed();
    echo($feed->get_permalink());
    echo($feed->get_base('href'));
    echo($item->get_base('href'));
}

I should also note that I am trying to get the exact feed so that I can know it's position in the feed array. I need this position because I have a 2nd array that has a list of categories that the feed belongs to.

È stato utile?

Soluzione

To get the feed's URL, you first need to get the item's feed object, then get its permalink:

$feed = $item->get_feed();
$url = $feed->get_permalink();

To get the feed URL itself, use $feed->subscribe_url() instead. Depending on redirects, this may or may not match the original passed in.

As for getting its position, you need to track this yourself in your own code. SimplePie does not (currently) maintain an ordered version of the feeds, so you need to do this on your end.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top