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’.
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>
The 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.