-
-
Save ScottPhillips/3201602 to your computer and use it in GitHub Desktop.
<?php | |
include_once(ABSPATH . WPINC . '/feed.php'); | |
if(function_exists('fetch_feed')) { | |
$feed = fetch_feed('http://example.com/feed/'); | |
if (!is_wp_error($feed)) : $feed->init(); | |
$feed->set_output_encoding('UTF-8'); // set encoding | |
$feed->handle_content_type(); // ensure encoding | |
$feed->set_cache_duration(21600); // six hours in seconds | |
$limit = $feed->get_item_quantity(10); // get 10 feed items | |
$items = $feed->get_items(0, $limit); // set array | |
endif; | |
} | |
if ($limit == 0) { | |
echo '<p>RSS Feed currently unavailable.</p>'; | |
} else { | |
// display first five feed items | |
$blocks = array_slice($items, 0, 5); | |
foreach ($blocks as $block) { ?> | |
<div class="feed-item column-one"> | |
<h1><a href="<?php echo $block->get_permalink(); ?>"><?php echo $block->get_title(); ?></a></h1> | |
<p> | |
<?php echo $block->get_date("l, F jS, Y"); ?> | |
<?php echo substr($block->get_description(), 0, 200); ?> | |
<a href="<?php echo $block->get_permalink(); ?>">Continue reading</a> | |
</p> | |
</div> | |
<?php } ?> | |
// display next five feed items | |
$blocks = array_slice($items, 5, 10); | |
foreach ($blocks as $block) { ?> | |
<div class="feed-item column-two"> | |
<h1><a href="<?php echo $block->get_permalink(); ?>"><?php echo $block->get_title(); ?></a></h1> | |
<p> | |
<?php echo $block->get_date("l, F jS, Y"); ?> | |
<?php echo substr($block->get_description(), 0, 200); ?> | |
<a href="<?php echo $block->get_permalink(); ?>">Continue reading</a> | |
</p> | |
</div> | |
<?php } | |
} ?> |
Your articles have helped me to learn a lot of interesting information on this topic and they are important material from which I can come up with many good ideas. Wordle
Hi. Can we use it for https://sasastatuscheck.co.za/? I think it will be very helpful. Thanks
Great solution for fetching and displaying RSS feeds in WordPress! It’s always nice to have a simple way to integrate external content. If you're looking for more tips and tricks on managing digital content, you might want to check out https://thedoorsofstone.online/. It’s a great resource with some solid insights.
Can we fetch the RSS feeds using this code? I want to fetch the RSS feeds from my Dixmax website. This application offers free content, and it's the best alternative to Netflix.
I am very grateful for this topic. There is a small recommendation for you that is Geometry Dash World, very happy if this game makes you relax.