Hi there,
I’ve had a search and I can’t see a similar post, so I thought I’d start my own. I have recently discovered and started to use SimplePie to integrate feeds into websites. It’s a great tool, and works well.
However, I now want to display just the first image from inside the content of a post with a caption, or short description. This is proving to be somewhat of a challenge for my naive brain.
Here’s my code:
<?php
//get the simplepie library
require_once('inc/simplepie.inc');
//grab the feed
$feed = new SimplePie('http://ameenakaracallender.blogspot.com');
//enable caching
$feed->enable_cache(true);
//provide the caching folder
$feed->set_cache_location('cache');
//set the amount of seconds you want to cache the feed
$feed->set_cache_duration(1800);
//init the process
$feed->init();
//let simplepie handle the content type (atom, RSS...)
$feed->handle_content_type();
?>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8”>
<title>RSS Feed Reader test page</title>
</head>
<body>
<h1>Ameena's Blog</h1>
<?php foreach ($feed->get_items() as $item): ?>
<h2><?php echo $item->get_title(); ?></h2>
<h4><?php echo $item->get_date(); ?></h4>
<?php echo '<img src="' .$item->get_first_image_url(). '"/>'; ?>
<?php endforeach; ?>
</body>
</html>
The get_first_image_url command, is obviously pseudocode, and I have no idea how to create that function, but essentially that’s what I need.
Any help would be great.
Many thanks in advance,
Micky