0

I have this issue I've been stuck with. It's when I load a page that has a feed. I put the feed in wp-admin; this usually work with other feeds but not sure why it's not working with this kind of feed.

When I load the feed I get this error:

[function.file-get-contents]: failed to open stream: Redirection limit reached, aborting in /wp-content/themes/wp-jqm-01-skolledarna/functions.php on line 624.

enter image description here

NOTE: The feed works in the browser.

It might be a parser problem and if it is I still can't resolve it.

Here is some code of the parser, from function.php :

class rss_php {

public $document;
public $channel;
public $items;

    /****************************
public load methods
    ***/
# load RSS by URL
    public function load($url=false, $unblock=true) {
        if($url) {
            if($unblock) {
    $this->loadParser(file_get_contents($url,         false,      $this->randomContext()));
            } else {
                $this->loadParser(file_get_contents($url));
            }
        }
    }
# load raw RSS data
    public function loadRSS($rawxml=false) {
        if($rawxml) {
            $this->loadParser($rawxml);
        }
    }

           /****************************
public load methods
    @param $includeAttributes BOOLEAN
    return array; ***/

# return full rss array
    public function getRSS($includeAttributes=false) {
        if($includeAttributes) {
            return $this->document;
        }
        return $this->valueReturner();
    }
# return channel data
    public function getChannel($includeAttributes=false) {
        if($includeAttributes) {
            return $this->channel;
        }
        return $this->valueReturner($this->channel);
    }
# return rss items
    public function getItems($includeAttributes=false) {
        if($includeAttributes) {
            return $this->items;
        }
        return $this->valueReturner($this->items);
    }

What could the problem be ?

EDIT: This is my rss function:

     function get_rss($url, $lang, $articles) {
$rss = new rss_php;
$rss->load($url);
$items = $rss->getItems();

// Sets the maximum items to be listed
$max_items = $articles;

$count = 0;

$html = '';
// Translates months to swedish
foreach($items as $index => $item) {
$pubdateForeignString = substr($item['pubDate'], 4);
$pubdateEnglishString = str_replace(array('maj', 'okt'), array('may', 'oct'), $pubdateForeignString);
$pubdate = date("Y-m-d", strtotime($pubdateEnglishString));

$html .= '
<ul class="rssList">
<li class="itemTitle"><a href="'.$item['link'].'" title="'.$item['title'].'" rel="external"><h2>'.$item['title'].'</h2></a></li>
<li class="itemText">'.$item['description'].'</li>
<li class="itemLink"><a href="'.$item['link'].'" title="'.$item['title'].'" rel="external" class="readmore">Läs mer</a><em>Publicerad: '.$pubdate.'</em></li>
</ul>';
$count++; //Increase the value of the count by 1
if($count==$max_items) break; //Break the loop is count is equal to the max_loop
}    
echo $html;
}
3
  • Which of these lines is 624? – s_ha_dum Jan 9 '13 at 15:25
  • Its the */ Public load methods */ # load by URL. if($unblock) { – M3o Jan 9 '13 at 15:27
  • What URL are you loading? – s_ha_dum Jan 9 '13 at 15:47
1

The problem is most likely with the address you are trying to fetch, and it is extremely unlikely it relates directly to your code.

You should check what url is being passed to file_get_contents to make sure it is the one you actually tried in the browser. If they are the same, it might relate to to other server doing different things based on user agent.

Side note: you are reinventing the wheel twice, Why don't you use the WordPress RSS API or at least the HTTP API?

Update per comment:

if all you need is to parse a standard RSS feed, then you should consider using the fetch_feed function. This function fetches the feed, parses it and caches the result for 12 hours by default.

2
  • I tried som other Rss-feeds in the same function and it works perfectly. I just was wondering if it has to do that if my function dosent support the aspx type of rss. Could you tell me more about the Rss API or share a link would be helpful ? – M3o Jan 11 '13 at 14:19
  • Answer updated with link – Mark Kaplun Jan 11 '13 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.