Skip to content

Instantly share code, notes, and snippets.

@johnheimkes
Created April 16, 2014 16:29
Show Gist options
  • Save johnheimkes/10903189 to your computer and use it in GitHub Desktop.
Save johnheimkes/10903189 to your computer and use it in GitHub Desktop.
Easy RSS feed
<?php
$rss = new DOMDocument();
$rss->load( 'http://wordpress.org/news/feed/' );
$feed = array();
foreach ( $rss->getElementsByTagName( 'item' ) as $node ) {
$item = array(
'title' => $node->getElementsByTagName( 'title' )->item(0)->nodeValue,
'link' => $node->getElementsByTagName( 'link' )->item(0)->nodeValue,
'date' => $node->getElementsByTagName( 'pubDate' )->item(0)->nodeValue,
);
array_push( $feed, $item );
}
$limit = 10;
for( $x = 0; $x < $limit; $x++ ) {
$title = str_replace( ' & ', ' &amp; ', $feed[$x]['title'] );
$link = $feed[$x]['link'];
$date = date( 'l F d, Y', strtotime( $feed[$x]['date'] ) );
echo '<p><strong><a href="' . $link . '" title="' . $title . '">' . $title . '</a></strong><br />';
echo '<small><em>Posted on ' . $date . '</em></small></p>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment