Post by Jacob on Jun 12, 2009 14:28:55 GMT -5
If you’re like me you probably have a blog as well as another site. I have found that an effective way to get vistiors to the blog is to link to it from the main site, assuming that that site is more popular. RSS (Really Simple Syndicate) is a way of syndicating your blog to other areas of the web. It is based on XML and generated automatically by Wordpress.
A PHP RSS parser is MagpieRSS. We will be using it in the following tutorial.
How to Install:
1. Download the most recent version of MagpieRSS from the above website.
2. Upload the “rss” folder to your web server.
3. Next we need to make a PHP include file for displaying the posts. Use the following code
4. Now you can include that file into your site wherever you want the feed to appear. Enjoy the free traffic!
A PHP RSS parser is MagpieRSS. We will be using it in the following tutorial.
How to Install:
1. Download the most recent version of MagpieRSS from the above website.
2. Upload the “rss” folder to your web server.
3. Next we need to make a PHP include file for displaying the posts. Use the following code
<?php
require_once('rss/rss_fetch.inc'); //Include the MagpieRSS include file
$url = 'http://yoursite.com/blog/?feed=rss2'; //Set a variable containing the URL to your blogs RSS feed
$rss = fetch_rss($url); //Retrieve the posts
$items = array_slice($rss->items, 0, 5); //Only show the first 5 posts (the second number can be customized to suit your needs)
$posts = '';
foreach ($items as $item) { //Loop through the items
$href = $item['link'];
$cat = $item['category'];
$title = $item['title'];
$date = $item['pubdate'];
$text = $item['content']['encoded'];
$text = preg_replace('/<img [^>]+\/?>/', '[image]', $text); //Replace images with [image]
$text = preg_replace('/<\/?[^>]+>/', '', $text); //Get rid of HTML
$posts .= "<li><a href=$href>$title</a> <em>".substr($text, 0, 100)."</em></li>"; //Print the current post title linked to the page on your blog, and the first 100 chars of the post
}
echo $posts;
?>
4. Now you can include that file into your site wherever you want the feed to appear. Enjoy the free traffic!