Created
February 11, 2014 13:31
-
-
Save ombagrao22/8934845 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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