Today, I figured out how to embed a Word Press post into an external website that resides on a separate server. with a little bit of help from Corvid Works and a page on SimplePie’s website, I got it working.
Here’s my sample page. This is a page on a client’s site that is currently pulling in posts from my cheese blog.
I had afew problems getting the code from Corvid to work exactly the way I wanted, which was to embed a full post, not just an excerpt. A quick search in the SimplePie documentation got me straightened out.
Follow these steps:
Stupid Assumptions
You know HTML and can edit an HTML file, know how to load and download files to a web server.
OK, here we go:
- Download SimplePie
- Unzip the file
- In the root directory of your website create a folder named: inc
- Open up the SimplePie folder that you just unzipped.
- Copy the simplepie.inc document into the root folder of your web site.
- Open the web page that you want to embed your wordpress posts into.
- If it is not a .php file, rename it to yourpagename.php.
- Insert the following code into the top of the page (above the <DOC TYPE> tag. (Note: In php, the // marks are comment tags. )
<?php
// Make sure SimplePie is included. You may need to change this to match the location of simplepie.inc.
require_once('./inc/simplepie.inc');
// We'll process this feed with all of the default options.
$feed = new SimplePie();
// Set which feed to process.Replace yoursiteurl with your web site address
$feed->set_feed_url('http://yoursiteurl.com/feeds');
// Run SimplePie.
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
?>
Once you’ve done this, decide where you want the posts to show up. In the HTML code, insert the following code:
<div class="header">
<h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1>
<p><?php echo $feed->get_description(); ?></p>
</div>
<?php
/*
Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
*/
foreach ($feed->get_items() as $item):
?>
<div class="item">
<h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
<p><?php echo $item->get_content(); ?></p>
<p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
</div>
<?php endforeach; ?>
Upload your page to your server and you should now see your latest posts, in full.
