Skip to content

Instantly share code, notes, and snippets.

@ombagrao22
Created February 11, 2014 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ombagrao22/8934845 to your computer and use it in GitHub Desktop.
Save ombagrao22/8934845 to your computer and use it in GitHub Desktop.
<?php
/*Code to retrieve RSS feeds from another website.*/
$rss_url = 'http://tech.firstpost.com/feed'; /*Specify your blog url to from where you want to retrieve posts*/
if( !class_exists( 'WP_Http' ) ) {
include_once( ABSPATH . WPINC. '/class-http.php' );
}
$request = new WP_Http;
$result = $request->request( $rss_url );
/*Check where data exists for requested url*/
if (!empty($result['body'])) {
$xml_data = simplexml_load_string( $result['body'] );
if (!empty($xml_data)) {
$xml_data = json_encode( $xml_data );
$xml_data = json_decode( $xml_data, true );
/*Here you can get whole array*/
if ( !empty( $xml_data['channel']['item'] ) ) {
$html = '<ul><p>Latest feeds</p>';
foreach( $xml_data['channel']['item'] as $post_data ) {
$html .= '<li><a href="'.$post_data['link'].'" title="'.$post_data['title'].'"> '.$post_data['title'].' </a></li>';
}
$html .= '</ul>';
echo $html;
}
}
}
/*Code ends here*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment