Display WordPress RSS on an External Website

Lately I’ve been adding custom WordPress RSS feeds on external websites. For example, we have a main news website for the University of Tennessee, Knoxville. Different initiatives and programs on campus like to have a feed on their home page (or internal page) of news stories about their initiative or program (excluding all the other news).

First, the posts in WordPress need to be tagged consistently and regularly. I know that’s a lot to ask, but you’ll see why it’s important right away (besides, it’s a best practice).

You’ll need to decide which tag of WordPress stories you’d like to embed on an external (non-WordPress) website. For our example, I’m going to use the tag “research” from the UTK news website, Tennessee Today.

Grab the URL of all posts tagged “research”: http://www.utk.edu/tntoday/tag/research/

In WordPress, all you need to do to create a custom RSS feed is add /feed/ to the end of the URL: http://www.utk.edu/tntoday/tag/research/feed/

Copy and paste the following code in to a PHP file:

<?php
// main calendar feed
// replace with your custom WordPress feed URL
$feedURL = "http://www.utk.edu/tntoday/tag/research/feed/";
// read feed into SimpleXML
$sxml = simplexml_load_file($feedURL);
foreach ($sxml->channel->item as $val) 
{
	$title = stripslashes($val->title); 
        $finalTitle = str_replace("’", "'",$title);
	$description = stripslashes($val->description);
        $finalDescription = str_replace("’", "'",$description);
	$link = stripslashes($val->link);
	$date = stripslashes($val->pubDate);
        $dateForm = substr($date, 0, 16);
	echo "<small>$dateForm</small>";
        echo "<p><a href='$link' target='_blank'>$finalTitle</a>
        <br />$finalDescription</p>n";
}
?>

Save and upload this PHP file to your website.

Voila! Custom WordPress RSS feed on your external (non-WordPress) website!


Leave a Reply

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