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.
<?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.
<strong>Latest articles on online marketing by Jim Westergren:</strong>
<br /><br />
<?php include("rss.inc"); ?>
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!
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!
[…] 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
[…] 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
[…] 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
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
Thanks, hehe.
No problem mate.
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
Nice site. Thank to work…
Great job guys…
I’m love this great website. Many thanks guy
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!
i want to earn throught blogging.
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?
John,
I can’t see the “funny” characters?
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.
Nice, useful tool. Thanks for sharing.
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
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.
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.
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.