How do I call for a latest blog post of a particular blog, without RSS?

mrweaver - January 5, 2008 - 21:26

I have a non-Drupal Website, and on that site I want to post the latest entry to a particular blog. I would like to figure out how to do this without enabling RSS for my entire Drupal site at this point.

<div id="blog">
Latest blog post: <?php [what do I put in here?] ?>
</div>

I could run an SQL query to pull it from the database, but the non-Drupal site is on a separate server. I think it would be simpler to call up the URL of the most recent node added under the blog. But, I don't know how to do that. Hence this message.

Thanks

mrweaver

RSS

yelvington - January 5, 2008 - 22:00

RSS is already "enabled" and is the simplest solution for what you describe. If the remote server is running PHP5, you'd need no more than half a dozen lines of code.

And, those lines of code, would they at all resemble...

mrweaver - January 11, 2008 - 12:49

<div>Latest blog post:
<?php $blog = 'http://www.website.com/?q=blog/4/feed';
$page = file_get_contents($blog);

    if(
$page){
   
$blog[] = array ();
   
'title' = t('Blog post title'),
   
'body' = t('Post'),
   
'path' = '?q=node/4/feed'
   
);
   
echo
$page['title'] . "<br />" . $page['body']; }?>
</div>

Thanks

Finished products are for decadent minds. -- Isaac Asimov

SimpleXML

yelvington - January 12, 2008 - 21:46

This isn't a Drupal issue, but rather a PHP question. If you have PHP5, use SimpleXML to parse the retrieved RSS data. The print_r() function will help you understand the structure of the XML object, or you can use http://us2.php.net/manual/en/function.simplexml-element-xpath.php to search for the parts you want.

http://www.onlamp.com/pub/a/php/2004/01/15/simplexml.html

If you are running PHP4, you can look at the PEAR add-on libraries for similar functionality.

Huh?

mrweaver - January 23, 2008 - 18:26

Okay, PHP-wise, my eyes are bigger than my stomach, if you catch my drift.

I have been over SimpleXML but the examples are all for an xml document. All I want to extract is the friggin' title of the latest blog post, and display it on a separate webpage. I have enabled Blopapi. How do I use simplexml with a URL as opposed to a file name?

mrweaver

RSS

yelvington - January 24, 2008 - 02:08

I have been over SimpleXML but the examples are all for an xml document.

RSS is XML.

Here is a barebones "fetch rss and display all the titles" example.

<?php
$str
= file_get_contents("http://drupal.org/node/feed");

foreach(
simplexml_load_string($str)->channel->item as $item)
{
    print
"<a href=\"$item->link\">$item->title</a><br />";
}
?>

Note that this will generate a call to your Drupal site every time the remote page is viewed. A more robust version would have error checking and, ideally, cache the result.

"RSS is XML."

mrweaver - January 26, 2008 - 20:26

"RSS is XML."

I know, but I wasn't sure if it was different for URLs.

is "channel" something I'm supposed to provide, or should it read literally "channel"?

When I display the Web page, instead of a link with a blog entry title, the code is displayed:

channel->item as $item){print "link\">$item->title
} ?>

This segment:

"link\">$item->title

is hyperlinked, but the URL is a mess.

Finished products are for decadent minds. -- Isaac Asimov

I have several ways I need

Jason Ruyle - February 6, 2008 - 01:45

I have several ways I need to use something like this, and wanted to know:

1. Limited number of items to show (lets say 5)

2. Show only one item (latest) with title and content

------------------------------
i do stuff

 
 

Drupal is a registered trademark of Dries Buytaert.