Du befindest Dich im Archiv vom ABAKUS Online Marketing Forum. Hier kannst Du Dich für das Forum mit den aktuellen Beiträgen registrieren.

Wordpress Feed einbauen auf meiner Startseite

Ajax, Hijax, Microformats, RDF, Markup, HTML, PHP, CSS, MySQL, htaccess, robots.txt, CGI, Java, Javascript usw.
Neues Thema Antworten
ypsie
PostRank 5
PostRank 5
Beiträge: 328
Registriert: 03.11.2003, 15:40
Wohnort: Wien

Beitrag von ypsie » 08.06.2005, 20:33

Hallo,

Ich habe einen Wordpress Weblog und das dazugehörige Feed:
https://www.wcheck.com/weblog/feed/

Nun möchte ich gerne auf meiner Startseite (index.php) automatisch den neuesten Blogeintrag anzeigen - am besten auf eine bestimmte Länge gekürzt.

Wie kann ich das realisieren?

mfg, julian

Anzeige von ABAKUS

von Anzeige von ABAKUS »

SEO Consulting bei ABAKUS Internet Marketing
Erfahrung seit 2002
  • persönliche Betreuung
  • individuelle Beratung
  • kompetente Umsetzung

Jetzt anfragen: 0511 / 300325-0.


Outman
PostRank 6
PostRank 6
Beiträge: 394
Registriert: 03.12.2004, 22:55
Wohnort: Orlamünde

Beitrag von Outman » 09.06.2005, 10:27

Hallo,

Code: Alles auswählen

<?php
function convertum&#40;$result&#41;&#123;
	$result = trim&#40;ucfirst&#40;$result&#41;&#41;;
	$result = preg_replace&#40;"/&#91;^_\.,&§\/\&#40;\&#41;\&#91;\&#93;=0-9À-ÿA-Za-zäöüßÄÖÜ\-\r\n &#93;/si", "", $result&#41;;
	return $result;
&#125;
class MagpieRSS &#123;
var $parser;
var $current_item = array&#40;&#41;;
var $items   = array&#40;&#41;;
var $channel  = array&#40;&#41;;
var $parent_field = array&#40;'RDF'&#41;;
var $current_field = '';
var $current_namespace = false;
function MagpieRSS &#40;$source&#41; &#123;
 $this->parser = xml_parser_create&#40; &#41;;
 xml_set_object&#40; $this->parser, &$this &#41;;
 xml_set_element_handler&#40;$this->parser, 'start_element', 'end_element'&#41;;
 xml_set_character_data_handler&#40; $this->parser, 'cdata' &#41;; 
 xml_parse&#40; $this->parser, $source &#41;;
 xml_parser_free&#40; $this->parser &#41;;
&#125;
function start_element &#40;$p, $element, &$attrs&#41; &#123;
 $element  = strtolower&#40; $element &#41;;
 $namespace = false;
 if &#40; strpos&#40; $element, '&#58;' &#41; &#41; &#123;
  list&#40;$namespace, $element&#41; = split&#40; '&#58;', $element, 2&#41;; 
 &#125;
 $this->current_field = $element;
 if &#40; $namespace and $namespace != 'rdf' &#41; &#123;
  $this->current_namespace = $namespace;
 &#125;
 if &#40; $element == 'channel' &#41; &#123;
  array_unshift&#40; $this->parent_field, 'channel' &#41;;
 &#125;
 elseif &#40; $element == 'items' &#41; &#123;
  array_unshift&#40; $this->parent_field, 'items' &#41;;
 &#125;
 elseif &#40; $element == 'item' &#41; &#123;
  array_unshift&#40; $this->parent_field, 'item' &#41;;
 &#125;
&#125;
function end_element &#40;$p, $element&#41; &#123;
 $element = strtolower&#40;$element&#41;;
      
 if &#40; $element == 'item' &#41; &#123;  
  $this->items&#91;&#93; = $this->current_item;
  $this->current_item = array&#40;&#41;;
  array_shift&#40; $this->parent_field &#41;;
 &#125;
 elseif &#40; $element == 'channel' or $element == 'items' &#41; &#123;
  array_shift&#40; $this->parent_field &#41;;
 &#125;
 
 $this->current_field = '';
 $this->current_namespace = false;
&#125;
function cdata &#40;$p, $text&#41; &#123;
 if &#40; $this->parent_field&#91;0&#93; == $this->current_field or
   ! $this->current_field &#41; &#123;
  return;
 &#125;
 elseif &#40; $this->parent_field&#91;0&#93; == 'channel'&#41; &#123;
  if &#40; $this->current_namespace &#41; &#123;
   $this->channel&#91; $this->current_namespace &#93;&#91; $this->current_field &#93; .= $text;
  &#125;
  else &#123;
   $this->channel&#91; $this->current_field &#93; .= $text;
  &#125;
 
 &#125;
 elseif &#40; $this->parent_field&#91;0&#93; == 'item' &#41; &#123;
  if &#40; $this->current_namespace &#41; &#123;
   $this->current_item&#91; $this->current_namespace &#93;&#91; $this->current_field &#93; .= $text;
  &#125;
  else &#123;
   $this->current_item&#91; $this->current_field &#93; .= $text;
  &#125;
 &#125;
&#125;
function show_list &#40;&#41; &#123;
 echo "<ol>\n";
 foreach &#40;$this->items as $item&#41; &#123;
  echo "<li>", $this->show_item&#40; $item &#41;;
 &#125;
 echo "</ol>";
&#125;

function show_channel &#40;&#41; &#123;
 echo "channel&#58;<br>";
 echo "<ul>";
 while &#40; list&#40;$key, $value&#41; = each&#40; $this->channel &#41; &#41; &#123;
  echo "<li> $key&#58; $value";
 &#125;
 echo "</ul>";
&#125;
function show_item &#40;$item&#41; &#123;
 echo "item&#58; $item&#91;title&#93;";
 echo "<ul>";
 while &#40; list&#40;$key, $value&#41; = each&#40;$item&#41; &#41; &#123;
  if &#40; is_array&#40;$value&#41; &#41; &#123;
   echo "<br><b>$key</b>";
   echo "<ul>";
   while &#40; list&#40; $ns_key, $ns_value&#41; = each&#40; $value &#41; &#41; &#123;
    echo "<li>$ns_key&#58; $ns_value";
   &#125;
   echo "</ul>";
  &#125;
  else &#123;
   echo "<li> $key&#58; $value";
  &#125;
 &#125;
 echo "</ul>";
&#125;
&#125; # end class RSS
class RSSCache &#123;
var $BASE_CACHE = './cache';
function RSSCache &#40;$base&#41; &#123;
 if &#40; $base &#41; &#123;
  $this->BASE_CACHE = $base;
 &#125;
 if &#40; ! file_exists&#40; $this->BASE_CACHE &#41; &#41; &#123;
  mkdir&#40; $this->BASE_CACHE, 0755 &#41;;
 &#125;
&#125;
function set &#40;$url, $rss&#41; &#123;
 $cache_file = $this->file_name&#40; $url &#41;;
 $fp = @fopen&#40; $cache_file, 'w' &#41;;
 if &#40; ! $fp &#41; &#123;
  return 
   array&#40;0, "Unable to open cache file for writing&#58; $cache_file"&#41;;
 &#125;
 $data = $this->serialize&#40; $rss &#41;;
 fwrite&#40; $fp, $data &#41;;
 fclose&#40; $fp &#41;;
 return array&#40;1, $cache_file&#41;;
&#125;
function get &#40;$url&#41; &#123;
 $cache_file = $this->file_name&#40; $url &#41;;
 if &#40; ! file_exists&#40; $cache_file &#41; &#41; &#123;
  return array&#40;0, '', "Cache file does not exists&#58; $cache_file"&#41;;
 &#125;
 $fp = @fopen&#40;$cache_file, 'r'&#41;;
 if &#40; ! $fp &#41; &#123;
  return array&#40;0, '', 
      "Failed to open cache file for reading&#58; $cache_file"&#41;;
 &#125;
 $data = fread&#40; $fp, filesize&#40;$cache_file&#41; &#41;;
 $rss = $this->unserialize&#40; $data &#41;;
 return array&#40;1, $rss, 'cache.success'&#41;;
&#125;
function check_cache &#40; $url &#41; &#123;
 $filename = $this->file_name&#40; $url &#41;;
 if &#40; file_exists&#40; $filename &#41; &#41; &#123;
  $mtime = filemtime&#40; $filename &#41;;
  return array&#40;1, $filename, $mtime&#41;;
 &#125;
 return array&#40;0&#41;;
&#125;
function serialize &#40; $rss &#41; &#123;
 return serialize&#40; $rss &#41;;
&#125;
function unserialize &#40; $data &#41; &#123;
 return unserialize&#40; $data &#41;;
&#125;
function file_name &#40;$url&#41; &#123;
 $filename = md5&#40; $url &#41;;
 return join&#40; '/', array&#40; $this->BASE_CACHE, $filename &#41; &#41;;
&#125;
&#125;
$CACHE_BASE = './cache';
$CACHE_AGE = 60*60; // one hour
function fetch_rss &#40;$url, $options=array&#40;&#41; &#41; &#123;
global $CACHE_BASE, $CACHE_AGE;
if &#40; $options&#91;'cache.no'&#93; &#41; &#123;
 list&#40;$remote_status, $rss, $msg&#41; = fetch_remote_rss&#40; $url &#41;;
 if &#40; $remote_status and $rss &#41; &#123;
  return array&#40;$rss, 1, 'success.remote'&#41;;
 &#125;
 else &#123;
  return array&#40;$msg, 0, 'fail.no_cache'&#41;;
 &#125;
&#125;
else &#123;
 $base = &#40; $options&#91;'cache.base'&#93; &#41; ? $options&#91;'cache.base'&#93; &#58; 
           $CACHE_BASE;
 $cache_age = &#40; $options&#91;'cache.age'&#93; &#41; ? $options&#91;'cache.age'&#93; &#58;
                $CACHE_AGE;
 $cache = new RSSCache&#40; $base &#41;;
 list&#40; $cache_status, $filename, $mtime&#41; = 
          $cache->check_cache&#40; $url &#41;;
 $age = time&#40;&#41; - $mtime;
 if &#40; $cache_status and $cache_age > $age &#41; &#123;
  list&#40;$status, $rss, $msg&#41; = $cache->get&#40; $url &#41;;
  if &#40; $status and $rss &#41; &#123;
   return array&#40;$rss, 1, 'success.cache'&#41;;
  &#125;
 &#125;
 list&#40;$remote_status, $rss, $remote_msg&#41; = fetch_remote_rss&#40; $url &#41;;
 if &#40; $remote_status and $rss &#41; &#123;
  $cache->set&#40; $url, $rss &#41;;
  return array&#40;$rss, 1, 'success.remote'&#41;;
 &#125;
 if &#40; $cache_status &#41; &#123;
  $rss = $cache->get&#40; $url &#41;;
  if &#40; $rss &#41; &#123;
   return array&#40;$rss, 1, 'success.cache.stale' &#41;;
  &#125;
 &#125;
 return array&#40;$remote_msg, 0, 'fail'&#41;; 
&#125;
&#125;
function fetch_remote_rss &#40;$url&#41; &#123;
list&#40;$status, $data&#41; = fetch_remote_file&#40; $url &#41;;
if &#40; $status &#41; &#123;
 $rss = new MagpieRSS&#40; $data &#41;;
 if &#40; $rss &#41; &#123;
  return array&#40;1, $rss, 'success'&#41;;
 &#125;
 else &#123;
  return array&#40;0, '', "Failed to parse RSS file&#58; $url"&#41;;
 &#125;
&#125;
else &#123;
 return array&#40;0, '', $data&#41;;
&#125;
&#125;
function fetch_remote_file &#40;$url&#41; &#123;
$fp = @fopen&#40;$url, 'r'&#41;;

if &#40; ! $fp &#41; &#123;
 return array&#40;0, "Unable to open remote file&#58; $url"&#41;;
&#125;
while &#40; ! feof&#40;$fp&#41; &#41; &#123;
 $data .= fread&#40; $fp, 1024 &#41;;
&#125;
fclose&#40;$fp&#41;;
return array&#40;1, $data&#41;;
&#125;
$url = $_GET&#91;'url'&#93;;
if &#40; ! $url &#41; &#123;
// $url einfach anpassen
$url = 'http&#58;//www.wcheck.com/weblog/feed/';
&#125;
list&#40; $rss, $status, $msg&#41; = fetch_rss&#40; $url &#41;;
function slashbox &#40;$rss&#41; &#123;
// $trenner einfach anpssen
$trenner='<br/><br/>';
$title = $rss->channel&#91;'title'&#93;;
$category = $rss->channel&#91;'category'&#93;;
$link = $rss->channel&#91;'link'&#93;;
$description = $rss->channel&#91;'description'&#93;;
foreach &#40;$rss->items as $item &#41; &#123;
 	$item&#91;"title"&#93;=convertum&#40;$item&#91;"title"&#93;&#41;;
 	$item&#91;"description"&#93;=convertum&#40;$item&#91;"description"&#93;&#41;;
	echo $item&#91;"title"&#93;.' / '.$item&#91;"category"&#93;.$trenner;
	$text = substr&#40;$item&#91;"description"&#93;, 0, strpos&#40;$item&#91;"description"&#93;, ".",50&#41;+1&#41;;
 	echo $text.$trenner;
 	echo $item&#91;"link"&#93;.$trenner;
&#125;  
&#125;
slashbox &#40;$rss&#41;; ?> 
 
Bitte schön.

mfg. Nico
Webhosting Partnerprogramm mit 2 Refebenen, PHP Webspace mit .de Domain ab 2 Euro, Zusätzlich suche ich Linkpartner zum Thema "Webmaster". Suchst du einem PHP Programmierer?

Antworten
  • Vergleichbare Themen
    Antworten
    Zugriffe
    Letzter Beitrag