This is part II of: Feed and sitemap generation Part I
I hope you were success in creating feed url and were very excited as i was.
I am working on this from long time as a part time after work and on weekends. I hope one day it will be in a condition when i'll be proud to release and be very excited for the contribution to the community. But for now i am thinking to pause uploading new files to google code but write few posts on new updates. This will help anyone to install new feature and understand what's going on.
Ok, thats too much talking, now Time for Sitemap generation. This is another community contribution on codeigniter that i used to create my sitemap. As it is not final but for now i tested this contribution like below. Rather than menu links, and other links, i'll be using last 50 post on my sitemap.
Contribution link on codeignitor: http://codeigniter.com/wiki/Google_Sitemaps/
STEP 1:
Download google_sitemap_pi.php and upload it to plugins directory.
STEP2: [frontend/controllers/tools/sitemap.php]
class Sitemap extends Controller { function Sitemap() { parent::Controller(); $this->load->helper(array('text')); $this->load->plugin('google_sitemap'); //Load Plugin $this->load->model('page_model'); } function index() { $sitemap = new google_sitemap; //Create a new Sitemap Object $posts = $this->page_model->getRecentPosts('50'); $item = new google_sitemap_item(site_url(), date("Y-m-d",time()), 'daily', '0.8' ); //Create a new Item $sitemap->add_item($item); foreach($posts->result() as $entry) { $link = preg_replace('|[^a-z0-9]+|i','-',strtolower($entry->pages_title)); //remove last dashes if any while(substr($link, -1) == '-') { $link = substr($link, 0, -1); } $link = "page/{$entry->menu_id}/{$entry->pages_id}/$link";// . $this->config->item('url_suffix')base_url(). $item = new google_sitemap_item(site_url($link), date("Y-m-d",strtotime($entry->pages_date)), 'weekly', '0.8' ); //Create a new Item $sitemap->add_item($item); //Append the item to the sitemap object } $sitemap->build("sitemap.xml"); //Build it... //Let's compress it to gz $data = implode("", file("sitemap.xml")); $gzdata = gzencode($data, 9); $fp = fopen("sitemap.xml.gz", "w"); fwrite($fp, $gzdata); fclose($fp); //Let's Ping google $this->_pingGoogleSitemaps(base_url()."/sitemap.xml.gz"); } function _pingGoogleSitemaps( $url_xml ) { $status = 0; $google = 'www.google.com'; if( $fp=@fsockopen($google, 80) ) { $req = 'GET /webmasters/sitemaps/ping?sitemap=' . urlencode( $url_xml ) . " HTTP/1.1\r\n" . "Host: $google\r\n" . "User-Agent: Mozilla/5.0 (compatible; " . PHP_OS . ") PHP/" . PHP_VERSION . "\r\n" . "Connection: Close\r\n\r\n"; fwrite( $fp, $req ); while( !feof($fp) ) { if( @preg_match('~^HTTP/\d\.\d (\d+)~i', fgets($fp, 128), $m) ) { $status = intval( $m[1] ); break; } } fclose( $fp ); } return( $status ); } }
STEP 3:
Create two files sitemap.xml.gz and sitemap.xml and give write permissions to both.
STEP 4:
Now time to generate sitemap and notify google about new sitemap. To do this just call this file as yoursite/sitemap.html. It will create sitemap for you and notify google about the new sitemap just created for it come and get it :)
All Done!!!
Good Luck.
kiddo posted on - Thursday 19th of March 2009 02:52:13 PM
Manset Soft Technology posted on - Sunday 9th of August 2009 03:31:42 AM
Damu posted on - Tuesday 3rd of November 2009 05:40:18 AM
Damu posted on - Friday 4th of September 2009 08:28:35 PM