350

professional dilettante

Magpie: Stupid simple rss parsing

http://magpierss.sourceforge.net/ For school we are doing small tech presentations where we share facts.  I figured it would be cool to aggregate my presentations on the domain i’m using for school.  Then I thought, it would be nice to just use my regular blog and then display the posts that relate to class/tutorials.  So after researching [...]

http://magpierss.sourceforge.net/

For school we are doing small tech presentations where we share facts.  I figured it would be cool to aggregate my presentations on the domain i’m using for school.  Then I thought, it would be nice to just use my regular blog and then display the posts that relate to class/tutorials.  So after researching simple php scripts to do that, came across Magpie.  Downloaded, dropped the directory onto my local server, and it pretty much just works.  Then I added a simple conditional since I only want to display the tutorials for class.

Here’s the resulting page aggregating the RSS items http://cdia.zhannes.webfactional.com/cdia-tutorials/ and below is the code.  To re-use this you have to put the code in php tags:

// this depends on your path to your magpie files
require('magpie/rss_fetch.inc');
$url = "http://professionaldilettante.com/feed";
echo "Site: ", $rss->channel['title'], "<br>\n";//magpie returns an associative array of items from your rss feed;
// lets loop over those items
foreach ($rss->items as $item ) {
$title = $item[title];
$url   = $item[link];
$desc  = $item[description];
$cat   = $item[category];// conditionally display all of the above IF the item $cat contains the string "web"
// this is b/c i only want to display certain posts
if(preg_match('/web/i',$cat)) {
echo "<p><a href=$url>$title</a></li><br>\n<cite>$cat</cite><br>\n $desc</p>";
}}

Now style to your liking :)

Leave a Reply

Required fields are marked with an asterisk (*), you may use these tags in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free

Most Recent Post

It’s been a long time, I shouldn’t have left you, part 1 …

But now I’m back.All official like.I do social stuff again.I see my friends.I’m moving into my own place again.And all that adult shit.

Categories

Content © professional dilettante
Proudly powered by WordPress
Theme designed by Artisan Themes

Entries (RSS)
Comments (RSS)

22 queries.
0.515 seconds.