joi, 28 august 2008

google sitemap for blogger blogs

one major drawback with using the Blogspot XML Feed as the Sitemap URL is that only new pages (max 25) will likely be submitted to the Sitemap,since the feeds are not a complete map.However,I will explain how to get your entire (new) Blogger Blogspot properly sitemapped using an external php script!

For that you will need a free web hosting account with php suported!We will create a xml file( our sitemap) using the following php code i wrote:

<?php
$rss="<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n
<rss version=\"2.0\">
<channel>\n
<title> your blog title</title>\n
<link>http://yourblogaddress.blogspot.com</link>\n
<description>your blog description</description>\n
<language>en</language>\n
<copyright> © 2008 yourname </copyright>\n
<ttl>5</ttl>\n
<pubDate>" .date("r") . "</pubDate>\n
<lastBuildDate>".date("r")."</lastBuildDate>\n";
//posts array
$posts=array(
 "1"=>array(
  "title"=>"Home page",
  "description"=>"home page",
  "link"=>"http://yourblogwebaddress",
  "guid"=>"http://yourblogwebaddress",
  "pubDate"=>date("r")
  )
 ,"2"=>array(
  "title"=>"your post title",
  "description"=>"your poast description",
  "link"=>"http://your-post-web-address",
  "guid"=>"http://your-post-web-address",
  "pubDate"=>"Tue, 26 Aug 2008 20:00:55 +0100"
  )
   
//here we have a single post!for every new post we will continue
//the above code,i.e. for the 3rd post will have:
//
// ,"3"=>array(
// "title"=>"your 3rd post title",
// "description"=>"your 3rd post description",
// "link"=>"http://your-3rd-post-web-address",
// "guid"=>"http://your-3rd-post-web-address",
// "pubDate"=>"3rd post(rfc style,see above)publish date" 
// )
//note that between "1","2","3",etc arrays we must have a comma(,)!After the last array
//we don't need that. 
);  
$s=sizeof($posts);//posts number
for ($i=1;$i<=$s;$i++){  $rss.="\n
  <title>".$posts[$i]["title"]."</title>\n
  <description>".$posts[$i]["description"]."</description>\n
  <link>".$posts[$i]["link"]."</link>\n
  <guid>".$posts[$i]["guid"]."</guid>\n
  <pubDate>" .$posts[$i]["pubDate"] . "</pubDate>\n
  </item>\r\n";
  }
$rss.="</channel>\n
  </rss>\n";
echo $rss;
?>


For every post in our blog we need to have an entry in $posts variable so if we have 300 posts we'll have to write a 300 entries array.It sounds a litle heavy but this way we will have every post in our blog sitemapped not just the last 25 posts!

If you don't know exactly your posts web address just enter your blogger account and go to "edit posts" then right click "view" and choose "copy link address" from the contextual menu!


Save this php code as a php file,i.e. sitemap.php,and upload the file to your free web hosting account !Say you have a free account at freewebaccount.com and the web address of php sitemap is http://freewebaccount/sitemap.php!

Go to your blogger account to "settings" ,"site feed"! For "Post Feed Redirect URL" you will write web address of your php sitemap,i.e.
http://yourfreewebaccount.com/sitemap.php.
Blogger will redirect all post feed traffic to this address.

 
Now you will have to add your site and your sitemap!For that you will find an excelent tutorial here:
http://theos.in/hakuna-matata/adding-google-sitemap-to-bloggercom-blog-account/


Bookmark and Share