I don't know if anyone will find this useful, but basically, you pass all your URLs one by one to this function like this : write_xml("http://www.yoursite.com","1.0"); The 1.0 is the priority level it will be given. If you don't specify one it defaults to 0.5 (just like google says it does.) It writes to "sitemap1.xml" after 50,000 URLs have been passed to the function, it closes that and initializes "sitemap2.xml" and starts writing URLs there... etc. When you reach the end, you call write_xml("END"); that tells the function that you are done sending URLs, it writes the closing tags to whatever sitemap # it is on, and closes it. So, if you have a loop that iterates through your database or forum or however you get your list of URLs, you just plug them in here, and it writes sitemap#.xml for you. It seems to work alright for me, it writes sitemap1.xml -> sitemap10.xml as I cycle through my database making all the URLs. global $handle, $counter, $file_number, $filename; $counter = 0; $file_number = 1; function write_xml($url,$priority = 0.5) { global $handle, $counter, $file_number, $filename; if($counter == 50000) { $file_number++; $counter = 0; // Attach end of file, and close it here. fwrite($handle,"</urlset>\n"); fclose($handle); } if($counter == 0) { // Open next file here. $filename = "sitemap" . $file_number . ".xml"; $handle = fopen($filename,"w+"); fwrite($handle,'<?xml version="1.0" encoding="UTF-8"?>' . "\n"); fwrite($handle,'<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">' . "\n"); } if($url != "" && $url != "END") { fwrite($handle," <url>\n"); fwrite($handle," <loc>$url</loc>\n"); fwrite($handle," <priority>$priority</priority>\n"); fwrite($handle," </url>\n"); } if($url == "END") { fwrite($handle,"</urlset>\n"); fclose($handle); } // Increment counter for every URL. $counter++; } Code (markup):
hey thats pretty nifty will defiantly help with better google indexing andrank.i never knew that function i appreciate it
Thanks! Oops.. I updated it, you have to declare the global variables outside the function and set them to their defaults. Also, a small example, for putting all the topics from a phpBB forum in the sitemap. You still need to connect to your database, and do all that, but just to show you how you can loop through the database and write out the URLs : mysql_select_db("phpBB_forums"); $result = mysql_query("SELECT DISTINCT(topic_id) FROM phpbb_posts"); while($row = mysql_fetch_array($result)) { $url = "http://www.yoursite.com/forum/viewtopic.php?t=" .$row['topic_id'] . "\n"; write_xml($url); } Code (markup):