viewing latest xml posts
Posted: Sat Nov 06, 2010 10:52 pm
i'm creating a blog using php and xml since i currently don't have access to mysql but i want to know how to display latest feeds, maybe 3 or so. and also have a next/previous page to the next/previous 3 posts, if possible without loading whole page just the blog box.
any help would be greatly appreciated.
Code: Select all
<?php
$doc = new DOMDocument();
$doc->load( 'blog.xml' );
$blog = $doc->getElementsByTagName( "post" );
$num = $blog->length;
for ($i = $num-1; $i >= 0; $i--){
$post = $blog->item($i);
$titles = $post->getElementsByTagName( "title" );
$title = $titles->item(0)->nodeValue;
$dates= $post->getElementsByTagName( "date" );
$date= $dates->item(0)->nodeValue;
$contents = $post->getElementsByTagName( "content" );
$content = $contents->item(0)->nodeValue;
echo "<h1>$title</h1> <d>$date</d> <p>$content</p>";
}
?>