如何显示来自其他网站的 RSS 源



我正在尝试显示一个博客:http://miletich2.blogspot.co.uk/在我的客户 Wordpress 网站上,正如我一直在寻找的那样,人们一直在推荐simple pie,他们的演示效果很好,但他们的 Wordpress 插件在 2 年内没有更新并且有很多错误。

有没有人知道另一个具有相同功能的插件?任何帮助将不胜感激!

您可以使用

fetch_feed函数。

例如,使用提供的博客显示 5 个帖子:

<?php 
    // Get a SimplePie feed object from the specified feed source.
    $rss = fetch_feed('http://miletich2.blogspot.com/feeds/posts/default?alt=rss');
    $maxitems = 0;
    if (!is_wp_error($rss)) { // Checks that the object is created correctly
        // Figure out how many total items there are, but limit it to 5.
        $maxitems = $rss->get_item_quantity(5);
        // Build an array of all the items, starting with element 0 (first element).
        $rss_items = $rss->get_items(0, $maxitems);
    }
?>
<ul>
    <?php if ($maxitems == 0) : ?>
        <li><?php _e('No posts found', 'text-domain'); ?></li>
    <?php else : foreach ($rss_items as $item) : ?>
            <li>
                <a href="<?php echo esc_url($item->get_permalink()); ?>">
                    <?php echo esc_html($item->get_title()); ?>
                </a>
                <span>(<?php echo $item->get_date(get_option('date_format')); ?>)</span>
            </li>
    <?php endforeach; endif; ?>
</ul>

最新更新