Strider Posted February 7, 2013 Report Posted February 7, 2013 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. Quote
Moderators Kyle Posted February 8, 2013 Moderators Report Posted February 8, 2013 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. Quote
Tom Posted February 8, 2013 Report Posted February 8, 2013 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>'; } Quote
Strider Posted February 8, 2013 Author Report Posted February 8, 2013 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] Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.