Semblance Digital Studio

Design and digital studio for startups, using WordPress as a CMS

  • Home
  • Services
  • Projects
  • Blog
  • Contact
You are here: Home / Blog / Wordpress / Use SimplePie and RSS to display latest WordPress blog post

Use SimplePie and RSS to display latest WordPress blog post

Posted on 25 July 2011 in Wordpress ♦ Estimate reading time: 3 minutes ♦ by Elzette Roelofse

SimplePie and feed in WordPress

I made a custom WordPress template for Printhouse Corporation. Printhouse has a blog with a seperate WordPress install (and subdomain). It was required to show an excerpt of the latest blog post from the seperate blog, in the footer of the official Printhouse website.

The way I thought about it, was to use the blog’s RSS feed to show the latest blog post. I found a bit of code from WpRecipes website. This only list a few titles of the latest blog posts. In this post I explain how to display the latest blog post from a different website, using SimplePie and the RSS feed in your WordPress website.

1. Install SimplePie Core Plugin

Most importantly use the SimplePie to make this work. As it says on the SimplePie website:

SimplePie is a very fast and easy-to-use class, written in PHP, that puts the ‘simple’ back into ‘really simple syndication’.

Thus, first install theĀ SimplePie Core WordPress plugin to load the core SimplePie API library.

2. Call RSS Feed

The code snippet start off by placing the following where you would like the latest post to show, eg. sidebar or footer. This is to call the RSS feed that is going to be used.

<?php
$feed = new SimplePie('http://www.exampledomain.com/feed/');
?>

3. Code snippet for the post excerpt

Then add the rest of the code to create the title and an excerpt of the latest blog post of the RSS feed.

<h3><a href="http://www.exampledomain.com">Example Heading</h3>
<?php $item = $feed->get_item() ?>
<h4><a href='<?php echo $item->get_permalink(); ?>'
  title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo $item->get_title(); ?></a></h4>
<p><?php print $item->get_description(); ?></p>

WordPress post from feedThe image on the left is an example of the result.

First a static heading. It depends on the website structure and where this go, which heading tags to use. Followed by the latest blog excerpt with the title as a link to the blog post.

Related Posts

  • WordPress Development from Dropbox with MAMP, Git and git-ftp (on Mac)WordPress Development from Dropbox with MAMP, Git and git-ftp (on Mac)
  • WordPress London October MeetupWordPress London October Meetup
  • Use Mosaic jQuery plugin for your WordPress Sticky postsUse Mosaic jQuery plugin for your WordPress Sticky posts

No Comments

Comments

  1. Jedediah says

    19 March 2014 at 3:57 pm

    I know this post is quite old, but would appreciate your help – How do I shorten the RSS description that’s output from being too long? Some of them (as you may know) are not configured very well to output an excerpt. Thanks!

    Reply
    • Elzette says

      20 March 2014 at 10:40 am

      It can be done with SimplePie – here is the reference: http://simplepie.org/wiki/tutorial/shorten_titles_and_descriptions

      Basically add the following shorten function (you can also grab it from the page at that link) to your function.php:

      function shorten($string, $length) {
      $suffix = '…';

      $short_desc = trim(str_replace(array("\r","\n", "\t"), ' ', strip_tags($string)));
      $desc = trim(substr($short_desc, 0, $length));

      $lastchar = substr($desc, -1, 1);
      if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';

      $desc .= $suffix;
      return $desc;
      }

      Then replace: get_description(); ?> with get_description(), 150); ?>
      The 150 is for the amount of characters, that can be changed accordingly.
      Hope that helps!

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

semblance logo enquiries@semblance.design © 2026
  • Email
  • Twitter
  • Instagram

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.