我对编码一无所知。我在web上做了大量的研究,并编写了以下代码来导入RSS提要并将其放置在我的模板中。问题是,虽然我得到了10个不同的标题、10个不同的日期、10张不同的图片,但我得到的每个项目都是相同的摘录。有人能帮我找出我做错了什么吗?
(我应该提到的是,我找到的代码没有包含get\\u节选,我补充说希望每个帖子都能得到节选,而不是所有帖子都是一样的。)
谢谢
<?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; ?>