WordPress is a great stand alone solution for blogging. You can quickly adopt themes and launch a blog site in under an hour. However, sometimes you will want to provide access to your content through another website or application. You can provide this content quickly with the WordPress feed using RSS. We will walk through an example in PHP that can have you linked to your blog in minutes.
The WordPress Feed
First, let’s verify you can see your feed. You access the feed through a simple change of your regular blog address. Add “/feed” to the end of the address in any browser. For example, our feed address is http://develpreneur.com/feed. The format of the feed varies depending on which type of permalinks you use. Note that you see code and text rather than formatted content and graphics. An RSS feed is just the text version of your site content.
Browsers display feed slightly differently so try it out in Firefox and Chrome for very different interpretations of the feed. There are also four types of feeds available. These feeds are RSS, RSS2, RDF, and Atom. By default, you will get the RSS format. That will work fine for our purposes.
PHP Example
The following code is all you need to display your blog articles on a web page. Format to your taste.
<?php
$feed = simplexml_load_file(‘http://develpreneur.com/feed‘);
foreach ($feed->channel->item as $item) {
$dc = $item -> children(‘http://purl.org/dc/elements/1.1/‘);
$content = $item -> children(‘http://purl.org/rss/1.0/modules/content/‘);
$title = (string)$item -> title;
$creator = (String)$dc -> creator;
$encoded = (String)$content -> encoded;
printf(‘<div class=”row” id=”%i”>‘,$count);
printf(‘<div class=”blog-main”>‘);
printf(‘<div class=”blog-post” >‘);
printf(‘<p class=”blog-post-title”>%s</p>‘, $title);
printf(‘<p>%s</p>‘, $encoded);
printf(‘</div></div></div><br/><br/>‘);
}
?>
Note that all you have to change is the URL value in the $feed variable assignment. The loop walks through each article and extracts the title, creator, and content. You can also grab other values. These include comments, a description, a link to the original article, category information, and more. This makes it easy to display your content in a variety of locations. You can also stream information from news sites and blend it into your newsfeed.
Further Reading
News feeds have a variety of uses so you might want to check out these for more ideas.
If you are just looking for a deeper explanation of RSS feeds and their usage this is a great article: http://www.digitaltrends.com/computing/how-to-use-rss/
[sgmb id=”1″]