Jump to content

Recommended Posts

Posted

As the title says I am creating an rss feed, specifically if you have a blog, and you want to show an rss feed on your main page, but don't want to go via another site to parse the feed for you. You never know, will that site suddenly go down or what. I have the module written, and it is not showing any errors, what I want help with is getting it to show on the front page. The code I have is:

RssFeed.php:

class RssFeed extends CodonModule
{
   public function index()
   {
   }
   public function parserSide($feedURL)
   {
       $rss = simplexml_load_file($feedURL);
       echo "<ul class='newsSide'>";
       $i = 0;
       foreach ($rss->channel->item as $feedItem) {
        $i++;
        echo "<li><a href='$feedItem->link' title='$feedItem->title'>" . $feedItem->title . "</a></li>";
        if($i >= 5) break;
       }
       echo "</ul>";
       Template::Show('rssfeed.tpl');
   }
}

and rssfeed.tpl:

<p><?php parserSide("'. echo SITE_URL?.'/blog/feed/"); ?></p>

Any help would be appreciated.

  • Moderators
Posted

Be sorta careful on the first node, clearly to me, that simplexml skips the first node... for example <something><rss>Hey!</rss></something>.

The $rss->something->rss won't do it's job, try something like $rss->rss.

Posted

public static function parserSide...

also remove

Template::Show('rssfeed.tpl');

and then wherever you want to show the list:

<?php RssFeed::parserSide(...

as a side note, the loop can be shortened a bit:

for($i = 0; $i <= 5; $i++){
$feeditem = $rss->channel->item[$i];
echo '<li><a href="'.$feedItem->link.'" title="'.$feedItem->title.'">'.$feedItem->title.'</a></li>';
}

Posted

Ok getting somewhere now, I have an error

[b]Warning[/b]: simplexml_load_file() [[url="http://malaysiava.org/function.simplexml-load-file"]function.simplexml-load-file[/url]]: I/O warning : failed to load external entity "malaysiava.org/blog/feed" in core/modules/RssFeed/RssFeed.php[/b] on line [b]9[/b] 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...