/ Published in: PHP
Note: This also uses a flat file to cache the results, be sure to also upload the 'rss_cache.txt' file.
Usage:
Usage:
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function get_news($url=''){ //save the rss file cache $validCache = false; $validCache = true; $feed = $data['feed']; } } if (!$validCache) { } //get the xml object foreach($news->channel->item as $item){ 'title' => $item->title, ); } return $result; } function display_news($news, $limit=3){ print "<ul class='news-feed'>"; $cnt = 0; foreach($news as $n){ if($cnt == $limit) return; print '<li class="news-item"><a href="' . $n['link'][0] . '" target="_blank">' . $n['title'][0] . '</a><p>'; print $n['description'] . ' <a href="' . $n['link'][0] . '" target="_blank"><strong>read more</strong> »</a>'; print '</li>'; $cnt++; } print '</ul>'; }
URL: http://stackoverflow.com/questions/6176561/caching-a-wordpress-rss-feed-with-php