Jim Westergren
About me, my projects, SEO, Web Development and Personal Development since 2005
"If we did all the things we are capable of, we would literally astound ourselves." - Thomas A. Edison

Tutorial: Feed your sites by blogging!

Notice: This article is from 2005. I have written a new one in 2009 about this same thing but much more good that can be read here.

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?

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 = "https://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!

30 Nov 2005

About the Author Jim Westergren Jim Westergren is a Swedish web entrepreneur currently living in Spain. He is happily married and has three lovely children. Some of his interests are web development, SEO and writing.
He is the Founder of DomainStats and N.nu. Read his .
This website was built using N.nu - try it yourself for free.    (Click here to renew the premium)(info & kontakt)