• Home
  • About Mitch
  • Speaking
  • Articles
  • Contact
  • Home
  • About Mitch
  • Speaking
  • Articles
  • Contact

Digital Strategist

WordPress Developer

Content Creator

Unapologetic Punk

Mitch Canter

  • X
  • Bluesky
  • GitHub
  • Twitch
  • YouTube
  • LinkedIn
Tutorial

Feed Me! Bring an RSS Feed Anywhere in your Site

CMDR Mitchcraft

Reading time: 2 minutes

Many of us are guilty of running multiple blogs – we have personal blogs, work blogs, and even blogs for our pets.  If you’re like me, however, you still like to show the different sides of yourself around your different sites.  WordPress’ built in RSS Widget does a great job at bringing external feeds into your site, but what if you want a little more control?  And what if you don’t want to constrain the feed to a widget, but give it a spot of prominence in a page template?  Well, that’s where SimplePie comes in – and the best part: it’s built into WordPress.

SimplePie is a very simple (hence the name) implementation of a php script used to scrape (fetch) a feed and display its contents.

Below is a self-made modification of the RSS sample given on the codex; this is a simple start, but it allows you to modify it like a typical WordPress loop (and structures it very similarly):

<?php if(function_exists(‘fetch_feed’)) {
include_once(ABSPATH.WPINC.’/feed.php’);
$feed = fetch_feed(‘#’); // Replace the hash mark with your feed URL
$limit = $feed->get_item_quantity(3); // specify number of items to show
$items = $feed->get_items(0, $limit); // create an array of items
}
if ($limit == 0) echo ‘<div>The feed is either empty or unavailable.</div>’; // Message to show if 0 items in feed
else foreach ($items as $item) : ?>
<div class=”post”>
<a class=”rsswidget” href=”<?php echo $item->get_permalink(); ?>”
title=”<?php echo $item->get_date(‘F j Y @ g:i a’); ?>”><h2><?php echo $item->get_title(); ?></h2></a>
<p><?php echo $item->get_date(‘F j Y’); ?></p>
<div class=”entry”>
<?php echo substr($item->get_description(), 0, 100); ?> // change 100 to number of characters to show
<a class=”fullpost” href=”<?php echo $item->get_permalink(); ?>”>read more</a>
</div>
</div>
<?php endforeach; ?>

rss feeds, SimplePie, WordPress
  • Yes, Another WordPress Update.  So?

    Yes, Another WordPress Update. So?

    Reading time: 1 minute

    WordPress released their press release about WordPress 3.0.4.  As soon as it did, I saw the WordPress hashtag on twitter light up – people complaining about having yet another security update.  I hate to get on a soapbox about this, but seriously – you’re going to complain about people working to make your site as…

    WordPress
  • WordPress 2.7 is Coming To Town!

    WordPress 2.7 is Coming To Town!

    Reading time: 1 minute

    The rumors are WordPress 2.7 will be coming to a download near you sometime tonight.  Release Candidate 1 is widely successful and I’m really looking forward to upgrading to the full version.  If you’re curious as to what the future entails, here are some great posts around the Internet showcasing the new goodness: The Official…

    WordPress