RSS Feed auf Homepage einbinden

hk

Angesehenes Mitglied
Abend,
Gibt es ein simples fertiges PHP Script mit dem ich einen RSS Feed in eine Homepage einbinden kann? Das also einfach die letzten 5 Artikrl des Feeds XYZ ausgibt (und ich es mit css formatieren kann)? Am besten mit cache. Bin leider mangels php kentnisse auf ein fertiges Script angewiesen.

Finde aber nur Javascript Lösungen.
 
Ja das geht mit Magpie RSS: http://magpierss.sourceforge.net/

Der folgende Code liefert dann die Titel in einer Liste (verlinkt).

CODE <?php
//Change the path to your MagpieRSS directory
require_once('magpierss/rss_fetch.inc');
require_once('magpierss/rss_cache.inc' );
define("MAGPIE_CACHE_ON", true);
define('MAGPIE_CACHE_DIR', '/home/xyz/public_html/cache');
define("MAGPIE_CACHE_AGE", "300");
define("MAGPIE_OUTPUT_ENCODING", "UTF-8");

//This is the function wrapper for the functionality.
//$url is an RSS feed URL string
function display_feed($url){
//Use MagpieRSS to grab the content of the feed
$rss = fetch_rss($url);
//If you're curious what it looks like, dump out the contents
//print_r($rss);
//We pull out the channel information.
//This could be used to add a title and link to the feed.
//If you were offering the feed to the public, you
//probably want to do that.
$channel = array_slice($rss->channel,0);
//The number of items we'll display
$items = array_slice($rss->items,0,5);
print("<ul>\n");
//Loop through the items
foreach ($items as $item){
//Grab the useful bits of the item
$id = $item['guid'];
$link = $item['link'];
$subject = $item['title'];
$content = $item['content']['encoded'];
$description = $item['description'];
//spit out the actual HTML.
print("<li><a href='$link'>$subject</a></li>\n");
}
print("</ul>");
}
//This is the mini web service portion
//Check for a feedurl on the request
if($_GET['feedurl']){
//Show the feed directly
display_feed($_GET['feedurl']);
}
?>
<?php
$php_feedurl = "http://xyz.com/feed/";
display_feed($php_feedurl);
?>


Edit: Du musst natürlich Magpie RSS herunterladen und auf deinem Server installieren.
 
Auch wenn der Thread schon etwas älter ist: Ich habe noch eine einfachere Lösung. Das PHP Script auf http://homepage-werbung.de/rss-newsfeed-au...ages-einbinden/ besteht aus weniger als 15 Zeilen Code und man braucht dafür nix zu installieren. Es benutzt eine Cache Datei, damit die Ladezeiten optimal bleiben. Services von Drittanbietern werden nicht benötigt.

In dem PHP Code braucht letztendlich nur die Feed-URL angepasst zu werden.
 
Zurück
Oben