SimplePie Helper

Feed 16 posts, 5 voices

Aug 21, 2008 07:59
Avatar
72 posts

To insert RSS feed in a Frog page, you can use a helper.

<pre><code> <?php<br /> use_helper('simplepie');</p> $feed = new SimplePie('http://simplepie.org/blog/feed/'); // or your rss url<br /> $feed->handle_content_type();<br /> ?> <p> <h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1><br /> <p><?php echo $feed->get_description(); ?></p> <?php<br /> foreach ($feed->get_items() as $item):<br /> ?><br /> <div class="item"><br /> <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2><br /> <p><?php echo $item->get_description(); ?></p><br /> <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p><br /> </div><br /> <?php endforeach; ?></code></pre>

(I hope Markdown will be ok...) or

example

 
Aug 21, 2008 08:00
Avatar
72 posts

Maybe one day I'll understand Markdown... (link is OK)

 
Aug 21, 2008 08:23
Avatar
396 posts

@oweb - about markdown... I make sure to put an empty line before and after my code blocks and make sure to insert at least six spaces before each line of code... that usually seems to work.

 
Aug 21, 2008 08:27
Avatar
72 posts

I will do that next time... Thank's

 
Aug 21, 2008 09:04
Avatar
820 posts

mvdkleijn wrote "...insert at least six spaces...", or a single tab-character, which is what I do.

(We'll sort this forum thing someday!!)

 
Aug 21, 2008 09:09
Avatar
820 posts

Btw - Oweb - did you see Ricks's post in the plugin forum?

 
Aug 21, 2008 09:14
Avatar
72 posts

No I didn't... Sorry

 
Aug 21, 2008 09:18
Avatar
820 posts

:) No need to apologize! If someone has only a single page pulling RSS, using Simplepie as a "Helper" might be a good solution! Thanks for this!

 
Aug 21, 2008 09:20
Avatar
820 posts

P.S for some reason the version of the link with the trailing / in #1 above gets a 404. This is the non-trailing-slash version. :)

 
Aug 21, 2008 09:29
Avatar
820 posts

It took me a little while to find where/how to set multiple feeds. This is straight off the SimplePie site:

$feed = new SimplePie();
$feed->set_feed_url(array(
    'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml',
    'http://rss.news.yahoo.com/rss/topstories',
    'http://news.google.com/?output=atom',
    'http://rss.slashdot.org/Slashdot/slashdot',
    'http://rss.cnn.com/rss/cnn_topstories.rss',
    'http://www.newsvine.com/_feeds/rss2/index'
));
$feed->init();
$feed->handle_content_type();
echo $feed->get_title();

So that's how. :)

 
Aug 21, 2008 10:33
Avatar
72 posts

Do you mean like this ?

 
Aug 21, 2008 11:09
Avatar
820 posts

Oui - comme ça! :) Do you know how (or if) SimplePie can group the RSS feeds under their source? Something like:

  • BBC News
    • feed 1
    • feed 2
    • feed 3
  • CNN
    • feed 1
    • feed 2
    • feed 3
  • Slashdot
    • feed 1
    • feed 2
    • feed 3
  • Yahoo News
    • feed 1
    • feed 2
    • feed 3
  • Etc.

I hope I got that Markdown right!!

 
Aug 21, 2008 12:17
Avatar
72 posts

I think it's easy...

http://tech.groups.yahoo.com/group/simplepie-support/message/1268

 
Aug 21, 2008 16:02
Avatar
286 posts

interesting. i'm a little confused though as to when to put stuff in the helpers folder and when to make it a plugin.

anyone?

 
Aug 21, 2008 16:15
Avatar
276 posts

I think helpers are more for simple tasks. The are like addons, with no backend feature. When you talk about plugin in Frog, you mean more a extension, because with it you can extend the backend and the frontend, making it much more complex then a helper.

 
Aug 21, 2008 16:15
Avatar
820 posts

I think plugins are site-wide, and helpers work per-page. mvdkleijn explained them, and I believe him. :)

 
Aug 21, 2008 16:39
Avatar
820 posts

So if you wanted to use SimplePie across several pages in a site, then you would want the plugin version in preference to the helper version. I think.