Using this post and the Tumblr API, I’m trying to embed the title of whatever the latest blog entry is on my website.
For some reason, I thought this would be a nice simple code, but it returns empty. Have I missed something obvious?
// Contents of includes/latest_blog.php
<?php
$request_url = 'http://###NAME###.tumblr.com/api/read?start=0&num=1';
$xml = simplexml_load_file($request_url);
$title = $xml->posts->post->{‘regular-title’};
$link = $xml->posts->post[‘url’];
echo 'Latest blog entry: <a href="'.$link.'">'.$title.'</a>';
?>
The website:
<p class="blog_title"><?php include('includes/latest_blog.php'); ?></p>
Thanks!
Actually the code is fine, it’s just that you’re using fancy Unicode quotation marks as in
‘regular-title’instead of the ASCII single-quote as in'regular-title'.Incorrect:
Correct:
For some reason, you must have missed the error message, so make sure you see all errors while testing new code: