I'm new to coding and know next to nothing. I've done a ton research on the web, and I foudn the following code to import an RSS feed and place it in my template. The problem is that while I get 10 different titles, 10 different dates, 10 different images, I get the same excerpt for each item. Can someone please help me figure out what I'm doing wrong?
(I should mention that the code I found did nit include get_the_excerpt, I added that hoping to get the excerpt for each post, not the same one for all of them.)
Thanks.
<?php
$feed = fetch_feed( 'http://example.com/feed/' );
if (!is_wp_error( $feed ) ) : // Checks that the object is created correctly
// Figure out how many total items there are, but limit it to 10.
$maxitems = $feed->get_item_quantity(10);
// Build an array of all the items, starting with element 0 (first element).
$rss_items = $feed->get_items(0, $maxitems);
endif;
?>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<div>
<?php
//Use regular expressions to find all images in the post
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $item->get_content(), $matches);
//Grab the first image to use as a thumbnail
$first_img = $matches [1][0];
//If an image exists, display it
if($first_img) {echo '<img src="'.$first_img.'" alt="'.$item->get_title().'" />';}
?>
//Display the post title as a link inside an <h5> tag
<h5><a href='<?php echo esc_url( $item->get_permalink() ); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo esc_html( $item->get_title() ); ?></a></h5>
//Display the item's publishing date
<p><?php echo $item->get_date('n/d/Y'); ?></p>
</div>
//Display the post exerpt
<p><?php echo get_the_excerpt(); ?></p>
<?php endforeach; ?>