Support » Plugins » Hacks » Adding custom RSS to home page

  • roger.bankes


    I wanted to create a custom page and for content display the latest posts as headlines with a summary. But I wanted to customize the look so I loaded these using some code to display the content from the site’s RSS feed rather than use a widget. I worked on this over a couple of days and had everything looking just the way I liked. But then when I visited the site, the RSS load was no loger working and giving the error… “failed to open stream – function.DOMDocument-load at was working ok yesterday and opening that link in a browser works ok. But my script can no longer access the feed directly!

    I did resolve the problem for the time being by using FeedBurner. That’s right, FeedBurner can access that link and publish my feed, and I can use the same script to open my RSS feed from Feedburner, but it doesn’t work when I open it from my site directly.

    		$rss = new DOMDocument();
    		$feed = array();
    		foreach ($rss->getElementsByTagName('item') as $node) {
    			$item = array (
    				'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
    				'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
    				'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
    				'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
    			array_push($feed, $item);
    		$limit = 5;
    		for($x=0;$x<$limit;$x++) {
    			$title = str_replace(' & ', ' & ', $feed[$x]['title']);
    			$link = $feed[$x]['link'];
    			$description = $feed[$x]['desc'];
    			$date = date('l F d, Y', strtotime($feed[$x]['date']));
    			echo '<div style="padding: 3px; padding-left: 25px;">';
    			$shorttitle = substr($title, 0, 70);
    			echo '<strong><a href="'.$link.'" title="'.$shorttitle.'">'.$shorttitle.'</a></strong>';
    			echo '</div><div style="padding: 3px; padding-left: 25px;">'.$description.'</div>';

    This code loads my RSS via FeedBurner but it no longer loads the same feed from … even though it’s the same feed!

  • The topic ‘Adding custom RSS to home page’ is closed to new replies.