Camen Design Forum

How to get latest posts

Jos

With the help from Stackoverflow and Google :)
Quick and dirty small script that grabs the entrys and sorts them per date. The interesting part is between //====.
Defining feeds this way suits me well. You prabably need to do something recursive. The last part i just use to test and display.
This works fine for me right now but probably not for others.

%PHP
<?
//Define feeds
foreach (glob("*/index.xml") as $filename) {
$feeds[] = $filename;
}
//================================
// Get all feed entries
$entries = array();
foreach ($feeds as $feed) {
$xml = simplexml_load_file($feed);
$entries = array_merge($entries, $xml->xpath('/rss//item'));
}

// Sort feed entries by pubDate (descending)
usort($entries, function ($x, $y) {
return strtotime($y->pubDate) - strtotime($x->pubDate);
});

//================================
foreach ($entries as $entry){

echo "$entry->author." : ".$entry->title."<p>".$entry->pubDate."</p><p>".strip_tags(mb_substr($entry->description, 0, 100, 'UTF-8')) . '...';
?> 
%

Append

(Leave this as-is, it’s a trap!)

Only the original author or a moderator can append to this post.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn