Tutorial: Feed your sites by blogging!

Are you also the kind of webmaster with 5, 10 or even 20 web sites with the plan of making a living only through your own sites?

  • How do you make sure that the content on all your sites are always fresh with related information?
  • How can you make sure that new pages you write are indexed in the search engines faster then ever?
  • How can you drastically increase your visitor traffic to new information you write?
  • And how do you manage all this by simply writing a page and clicking one button and it’s done?

I have the solution, it is called feeding your sites from your blog.

To see an example I give you NetMarketing.us, the data on the right are coming from a feed from my blog, total automatically. This also makes the articles unique. In a later blog post I will give you all the feeds I have so you can see it.

I give you here the tutorial.

  1. Categorize all your web sites in different categories.
  2. Then make a blog and I personally recommend using Wordpress.
  3. Create categories on the blog that fits your sites. You can make some subcategories called “Articles”.
  4. Then make some posts.
  5. Save the following in a file called rss.inc on the same directory were you have the page to get the feed:
  6. <?php
    /*
    Created by Global Syndication's RSS Parser
    http://www.globalsyndication.com/rss-parser
    Modified by Jim Westergren
    */
    set_time_limit(0);
    
    #######  The below URL is for your feed:
    $file = "http://www.jimwestergren.com/category/online-marketing/articles/feed/";
    
    $rss_channel = array();
    $currently_writing = "";
    $main = "";
    $item_counter = 0;
    
    function startElement($parser, $name, $attrs) {
       	global $rss_channel, $currently_writing, $main;
       	switch($name) {
       		case "RSS":
       		case "RDF:RDF":
       		case "ITEMS":
       			$currently_writing = "";
       			break;
       		case "CHANNEL":
       			$main = "CHANNEL";
       			break;
       		case "IMAGE":
       			$main = "IMAGE";
       			$rss_channel["IMAGE"] = array();
       			break;
       		case "ITEM":
       			$main = "ITEMS";
       			break;
       		default:
       			$currently_writing = $name;
       			break;
       	}
    }
    
    function endElement($parser, $name) {
       	global $rss_channel, $currently_writing, $item_counter;
       	$currently_writing = "";
       	if ($name == "ITEM") {
       		$item_counter++;
       	}
    }
    
    function characterData($parser, $data) {
    	global $rss_channel, $currently_writing, $main, $item_counter;
    	if ($currently_writing != "") {
    		switch($main) {
    			case "CHANNEL":
    				if (isset($rss_channel[$currently_writing])) {
    					$rss_channel[$currently_writing] .= $data;
    				} else {
    					$rss_channel[$currently_writing] = $data;
    				}
    				break;
    			case "IMAGE":
    				if (isset($rss_channel[$main][$currently_writing])) {
    					$rss_channel[$main][$currently_writing] .= $data;
    				} else {
    					$rss_channel[$main][$currently_writing] = $data;
    				}
    				break;
    			case "ITEMS":
    				if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
    					$rss_channel[$main][$item_counter][$currently_writing] .= $data;
    				} else {
    					$rss_channel[$main][$item_counter][$currently_writing] = $data;
    				}
    				break;
    		}
    	}
    }
    
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    if (!($fp = fopen($file, "r"))) {
    	die("could not open XML input");
    }
    
    while ($data = fread($fp, 4096)) {
    	if (!xml_parse($xml_parser, $data, feof($fp))) {
    		die(sprintf("XML error: %s at line %d",
    					xml_error_string(xml_get_error_code($xml_parser)),
    					xml_get_current_line_number($xml_parser)));
    	}
    }
    xml_parser_free($xml_parser);
    
    // output HTML
    ### This is the channel title which is not needed #### print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . ""); 
    
    if (isset($rss_channel["ITEMS"])) {
    	if (count($rss_channel["ITEMS"]) > 0) {
    #### In the line under this one is a number, 10, that number is how many posts to display on the feed.
    		for($i = 0;$i < 10;$i++)  {
    			if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
    			print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a>");
    			} else {
    			print ("\n<div class=\"itemtitle\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
    			}
    			 print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />"); 		}
    	} else {
    		print ("<b>There are no articles in this feed.</b>");
    	}
    }
    
    ?>

    On the lines were you see ###, those are instructions. To get the URL of your feed just go to the category you want to give feed and add /feed/after that URL.

  7. Then open the URL you want to have the feed and add something like:
  8. <strong>Latest articles on online marketing by Jim Westergren:</strong>
    
    <br /><br />
    
    <?php include("rss.inc"); ?>
  9. To change the style of the feed just add the classes itemtitle and itemdescription to your CSS file. Or just change the last part of the script which is the HTML output, you can even have tables with background etc.
  10. Then do the same on your other sites.

When you do a blog post you can have it into several categories and on your feeds you can for example only take those in the Article category so you don’t get any low quality posts on the feeds.

If you write a description on “Excerpt” of the post then that is displayed on the feed.

There is also a way to have several feeds from the same blog from different categories on the same web page by just having a different name on the rss.inc and changing the following words on the script: startElement, endElement and characterData. You can see an example here.

When you have set this up on let’s say 10 sites, you will see how incredible this is.

Good luck!

18 responses » Leave a comment
  1. Solicitors Mortgages said on November 30, 2005 at 4:31 pm

    Thanks a lot Jim, nice tutorial. I am afraid i will be harrassing you via PM if i cannot get it set up properly ;)

    GEM

  2. Jim Westergren said on November 30, 2005 at 6:57 pm

    Thanks, hehe.

    No problem mate.

  3. Chris Andrews said on November 30, 2005 at 11:34 pm

    Good explanation of a powerful technique. I’ve been using this technique (although without the description) to cross promote my sites.

    I’ve also used rss feeds from big name sites to keep the content fresh on my pages.

    I’ve never combined the two ideas! How silly do I feel?

    Thanks Jim :)

  4. truman said on May 29, 2006 at 5:53 am

    Nice site. Thank to work…

  5. geol said on May 29, 2006 at 6:27 am

    Great job guys…

  6. huntingdon said on May 29, 2006 at 6:29 am

    I’m love this great website. Many thanks guy

  7. Cem Gencer said on July 23, 2006 at 3:09 am

    nice and nifty idea, which i will definitely use on my sites one for music, one for tutorials and one for a foreign seo-experiments. i worried about multiple themes gave a minus, but this simple script is THE tool for me it seems. thanks a lot!

  8. i want to know blogging said on January 19, 2007 at 4:31 pm

    i want to earn throught blogging.

  9. John Aitchison said on March 10, 2007 at 1:30 am

    Hi Jim,
    I got this going just fine, but I see “funny” characters in the feed display on the destination site .. have a look at http://datasciencesresearch.com/ which displays the feed from dsanalytics.com/dsblog/feed

    Do you have an idea about what is causing this, and what I should do about it?

    Also, it seems to me that google is tightening up on links that have the same text - so maybe this technique could be considered bad practice by google? Any comment?

  10. Jim Westergren said on March 12, 2007 at 1:15 pm

    John,

    I can’t see the “funny” characters?

    Also, it seems to me that google is tightening up on links that have the same text - so maybe this technique could be considered bad practice by google? Any comment?

    Should not be any problem as long as you have most of the text as unique. But if it worries you, you can take out the descriptions and only display the links.

  11. Text Link Auction said on June 6, 2007 at 11:28 pm

    Nice, useful tool. Thanks for sharing.

  12. Benny Kvist said on July 6, 2007 at 7:28 pm

    Hi jim.

    I tried to include your feed on my page, http://www.microfinanceinfo.com
    But nothing is showing up there. What am i doing wrong?
    /Benny

  13. Jon Parker said on July 9, 2007 at 12:58 pm

    I get the following error message in the error logs of the site I have this running on:

    PHP Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit in safe mode in /home/masvi/public_html/loans2/inc/rss.inc on line 8

    Any ideas what is causing it and how to fix it? It appers to be working fine except the warning in the logs (and I hate looking at my logs and seeing the errors).

    Thanks.

  14. mustafa said on September 20, 2007 at 3:29 pm

    Should not be any problem as long as you have most of the text as unique. But if it worries you, you can take out the descriptions and only display the links.

  15. Web Tasarim said on October 2, 2007 at 4:55 pm

    PHP Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit in safe mode in /home/masvi/public_html/loans2/inc/rss.inc on line 8

    Jon Parker said this code is correct.

RSS feed for comments on this post or Track with co.mments

Leave a Comment

To quote: <blockquote>text to quote</blockquote>

Link to This Page

If you found this page useful, consider linking to it.
Simply copy and paste the code below into your web site (Ctrl+C to copy)
It will look like this: Tutorial: Feed your sites by blogging!

Pingbacks
  1. […] Yes feeds! It´s so obvius but yet many people miss it! I was planning to write some more about it here but my friend Jim already wrote a good article about it. Take a look at Jim´s article : here […]

    Pingback by Marcus Network » Blog Archive » This rocks! — December 3, 2005 @ 1:18 am

  2. […] Use your blog to provide content for other sites, a great idea: Tutorial: Feed your sites by blogging […]

    Pingback by PlanetStrange - UK magic blog by magician Dan Gifford » Tutorial: Feed your sites by blogging — February 2, 2007 @ 12:02 pm

  3. […] Now the problem is that I want to use it in conjunction with XML parsing (RSS is XML, remember) and my starting point was a code snippet from Jim Wintergren (http://www.jimwestergren.com/tutorial-feed-your-sites-by-blogging/ which owes a lot to http://www.shadow-fox.net/site/tutorial/37-Building-Content-By-Parsing-RSS-Feeds-With-PHP ), which breaks just about here […]

    Pingback by DataSciences Analytics » A cURLy tale – PHP and feeds and text mining — February 26, 2007 @ 9:23 am



Post Navigation by Category

Previous post in category: Huge amount of links added to my new site

Next post in category: Changed theme