I spent a little time and worked up some php code that generates a Google Sitemap from a WordPress site. The php code generates a Google Sitemap xml file with all your posts ordered by time – newest posts first. Here’s a link to my Google Sitemap so you can see how it looks.
I’m sure there are ways to improve on my code so go right ahead. If you do, just leave me a comment. I might want to download it from you.
Just copy this code into a php file.
You can refer back to my previous post to read more about the Google Sitemaps Protocol and how you can submit your Google Sitemap.
Update: Wanted to point out that this generates a Google Sitemap from all your posts. There is no page support or category support. It is real basic and can definitely be improved.
Update #2: I won’t be writing a plugin for this since Arne Brachhold has already written a great one. Thanks Arne.
Quick and nice start to help the community use this new Google feature, thanks for it.
I have a couple suggestions that are easy to implement :
use gzencode to produce a lighter .tgz instead of raw xml. Since Google accepts gzipp’ed documents, let’s not waste our bandwidth
modify your SQL query : not only “post_status = ‘publish’” but also “post_status = ‘static’” to indexes pages as well as posts
you could probably fine tune the priority rather easily : for example checking post_modified, and giving a different priority depending on how old the post is.
This said, I (we ?) have no clue of what Google will do with this priority …
You could add a “loc” entry for categories as well. I find my category pages (/category/linux/ etc..) are quite often accessed from Google searches, so I think it’s important they’re well crawled and indexed as well.
I also have a few ideas of further improvements that will be quickly needed
You could easily make your script a plugin that would be run when a post is either created or modified.
The thing I’d suggest here is that the sitemap is updated when a post is modified, and that it is updated and submitted to Google when a post is created (with maybe a maximum number of daily submission, although I couldn’t find any guidelines about this on Google’s pages)
This would make another feature quite mandatory : it’d be a waste of computer time to generate the whole sitemap each time a post is created, especially on large blogs with numerous posts. A workaround would be to make incremental updates.
It could be done by dynamically generate entry for latest post and merge it with a static file containing all previous posts.
So. This were my first thoughts about your work. Again, thank you for being quick on this.
Pingback: planetOzh
Many thanks for that – however, just a quick question – is this going to be difficult to work with presenting an individual feed for individual category groups, or will it only work with generating a feed for the entire WP site?
Pingback: Search Engine Roundtable
Pingback: ????????
Pingback: Microsiervos
I knew somebody would come out with this. Great job! I’ll try it out later today.
Awesome! Thanks!
Pingback: Lockergnome's Internet Marketing
Pingback: Un Passo Al Giorno
Pingback: jarkolicious
Awesome…thanks for this nice little script!
Thanks – absolute plug-n-play. This will be interesting to see how it goes.
Sarah
I hope you dont mind but Ive made your script output a gzipped version of the sitemap to save bandwidth.
heres the changed code…
http://thedt.net/random/sitemap.txt
awesome, thanks for the code.
Pingback: fozbaca.org
Ditto, thankyou :O)
Hey there! Thanks for the idea, I spent a few minutes working it into my own CMS.
http://www.hinkybox.com/devpages/gsitemap.phps
Re: categories & sitemap sitemap; I have some down time so if I come up with
something psuedocodey I will comment again.
One little question, as I am not very familiar with the inner workings of WordPress: Are all dates UTC/Zulu?
Thanks man!
Pingback: WebMaster View
With regard to the suggestion to have the script submit new ones every so often, the guidelines for Google’s own generator say a maximum of once per hour.
Pingback: netdancerplanet.info
Wow, thanks for all the comments – I’ll be out this weekend but I’ll try and improve the script during next week.
Thanks for the great script guys. I’ve managed to get my sitemap up and running but Google doesn’t like the code somehow.
When submitted, Google returns the error ‘We couldn’t find the Sitemap at the location you provided. Please make sure the Sitemap URL is correct and resubmit your Sitemap.’
Anyone else come across this yet?
I’ve also modded your script, it now includes category support and page support. Couldn’t get it to gzip though for some reason. Here’s my edited sitemap code
Pingback: I VISION
Pingback: juque § Weblog
Hi,
i found another one which also includes static pages. The priority gets calculated by the number of comments relative to the whole number of comments. Nice coded.
http://www.arnebrachhold.de
Thanks for the generator, works great. Thankyou!
Hello
I think you need to use utf8_encode to be on the safe side…
echo utf8_encode(”); ?>
always
1.0
get_results(“SELECT * FROM $wpdb->posts WHERE post_status = ‘publish’ ORDER by post_modified DESC”); ?>
ID)); ?>
post_modified, false)); ?>
daily
0.8
oops, sorry about that last post. That is pretty ugly.
try this:
http://goofymoo.com/oops.txt
take care
Ozh said, “The thing I’d suggest here is that the sitemap is updated when a post is modified [...] it’d be a waste of computer time to generate the whole sitemap each time a post is created, especially on large blogs with numerous posts. A workaround would be to make incremental updates.”
Except you can have multiple sitemaps. So, have a sitemap for everything prior to the current month and a second for things added this month. Only the second needs to be recreated and shipped to Google every hour.
So, finally… I tried to comment (and trackback) already yesterday with a new script that includes static pages (as Ozh suggested) and also dt’s gzip-compression.
Best thing on this script is the frequency the sitemap is generated. When requested, it is checked whether the last backup is more recent than the last post modification. If necessary, a new backup is generated and eventually, this backup is returned. I’ll see to it to include the new ideas, too.
Get the script at http://sidney.ws4f.us/2005/06/04/keeping-pace-with-google
Oh, and it seems to work with Google, I submitted the map yesterday. Still have to see if they complain now.
Sid.
I merged your script with the one by Arne Brachhold, so that the final script also has category pages and can be configured. Also it generates the sitemap only if necessary (it does a backup to a certain file, and if nothing has changed, only the backup is returned.). And I included the idea by dt for gzip.
Hope, you’re okay with this.
Download at http://sidney.ws4f.us/2005/06/04/keeping-pace-with-google
Sid
Thanks …
I submitted sitemap of my blog thanks to your script … but I get Parsing error. why?
Milos
Well, I can only guess. The script works good for me (http://sidney.ws4f.us/sitemap.php), so I’m not sure what the problem is. Can you give me the address or the error? [email: sidney[nospam]440@gmail.com]
I have made a very simple explanation and form to create a sitemap. Would love your comments. No PHP or scripting knowledge is required.
Ben
http://www.googlesitemap.info
i also kompared one with gz support.
here you can see it.
I found another sitemap script with a configuration user interface (WordPress plugin). Look at Google Sitemap Generator v2 (BETA)
Richard
Good work on the script, I used some ideas in it for one tat I was working on to do the same basic thing.
I recommend everyone to use Arne’s plugin – it’s great. Saved me the effort in writing my own.
Nice… I will use it. Thanks
Nice… I will use it. Thanks
The Google Sitemap Generator for WordPress works very good. Thanks for the link!
Guys That a great site- great job done thanks…
Some competition for Arne
: I converted my original remix into a real plugin for WordPress. Includes real timezones and saves you some time by only generating if really necessary. Download at my site.
Sid
you just got a link from google
http://code.google.com/sm_thirdparty.html
Thanks for pointing that out Aaron
Sorry to spam so much (delete the old posts by me, if you like), but I just wanted to let you know: I added a feature to my plugin that informs Google every time you publish, edit or delete a post. Never again having to submit your sitemap manually.
Also, most (all?) features of Arne Brachhold’s plugin are in it, and real timezones and a min priority for posts (it’s no good if a post has a priority of “0.0″).
http://www.sidney.ws4f.us/2005/06/13/google-sitemap-plugin-sidney-edition
Sid
Pingback: Home of Arne Brachhold
Pingback: # k u k i e » WordPress ?????
this is exactly what i’ve been looking for, thanks!
Thanks Michael, you are the man. I love the WP community.
here is my rating for your great plugin:
http://www.gangavalli.com/blog/2005/08/16/google-sitemap-generator-plugin-for-wordpress/
Good luck!
Pingback: alexmoreno.net » google sitemap
How WordPress in googlemap?
Pingback: juque § weblog
Pingback: » Mr. Ploppy’s Monday Tool List - Volume XXIV - Stuntdubl - SEO Consultant
Pingback: OddThinking » Judging the initial WordPress Google Sitemap Plugins
Pingback: OddThinking » Judging the WordPress Google Sitemap Plugins - Redux
It may be a good idea to to validate the sitemap before a submission. Since accepted sitemaps get downloaded daily, there is no need for resubmits. In the meantime Google has even added crawler problem reports, great move.
Pingback: ? ? ? ? » Blog Archive » WordPress?sitemap??
For anyone who’s interested… I have a script that turns your Google compliant XML sitemap into a Yahoo compliant sitemap that you can submit to Yahoo.
It’s free.
http://www.ielliott.com/2005/10/31/google-to-yahoo-sitemap/
Pingback: I VISION » Google Sitemaps help indexing
Pingback: kukie » WordPress ?????
Pingback: Php???????? » Google Sitemap Plug-in for wordpress
Pingback: Php???????? » Google Sitemap Plug-in for wordpress
Pingback: Working Blogger»Blog Archive » Google Sitemaps for Bloggers
Pingback: Home of Arne Brachhold » Google Sitemap Generator for WordPress 2.5
Pingback: Frank Beier
Thanks for providing this plugin, until recently I was using it for my sitemap. After spending some time revitalizing my website I came back here to find the link to the WordPress plug-in. I have no migrated, but I appreciate the work you did.
I looking for how to generate sitemaps, this tool helped me to generate for my wordpress site
Thanks for the comments everyone.
Hello All,
I have create http://www.fibre2fashion.com/sitemap.txt
for google sitemap submission but still not varified.
how to used UTF -8 Code in the same sitemap.txt file?
Any online tools or software available to create sitemap.txt for google sitemap.
Waiting for your feedback.
Pingback: Google Sitemaps to Improve Indexing » Search Engine Optimization » SEO For Wordpress
I am using the Plugin and it works great from Day one.
If your site is not verified than you missed making the dummy Google File and uploading it to your root folder on your server. Once you have the file up there click on the “verify” button.
All that verify means is that the dummy file has not been found or checked yet.
Follow the instructions given by Google on that point and all will be well.
I am using the Plugin and it works great from Day one.
Pingback: Addio monti. . . | Central Scrutinizer - [ il web in 272 comode rate ]
Pingback: aoiro-blog » Google Sitemaps (BETA)?WordPress
Pingback: Bagak.Com
Pingback: BLog | kaNg aSep » Breaking Down Google Sitemaps XML
Thanks – absolute plug-n-play. This will be interesting to see how it goes.
Pingback: shupe.ca » Weblog for shupe.ca Ramblings from the shupe family.
Pingback: blog.nas » Generate Google Sitemap for WordPress
Pingback: Wordpress30?????? | BiZwiKi.CN - ?? PK ??
Thanks for the code, great job, it works so pretty !!
Pingback: 23rd World » Google’s Sitemap Buzz
Pingback: Blog » Blog Archive » Free Online - Web - Hosting
Pingback: Google Site Maps at Galder.net web –> blog
Hello!
Very good work, simple and eficient code! Thanks a lot. I have noticed an “error”, if you publish some post to be appeared in the future (set future time to them, useful if you are going to be inactive in a comming period…), this script does not respect it and show them.
Another plugin I have showed, as this one http://www.arnebrachhold.de/2005/06/05/google-sitemaps-generator-v2-final has the same problem.
I have updated the query to:
$t = time ();
$today = date (“Y-m-d H:i:s”,$t);
$sitemap = $wpdb->get_results(“SELECT * FROM $wpdb->posts WHERE post_status = ‘publish’ AND post_date
Pingback: Google Sitemaps (BETA) « :: plasticdreams ::
Pingback: BoGoMo » Blog Archive » [?]????? ?? ? ? ?? ????
Omg! thx! i’ve fighting with this problem alot of time!… thx ) article really helped
Pingback: 23rd World » Google Sitemaps Explained
Pingback: ¸µ¥Á¥ã¥Ã¥È¥ì¥Ç¥£¡ª¥¬¥Ã¥Ä¥ê·î¼ý100Ëü½÷µ¯¶È²È¤Ø¤ÎÆ»
Thanks for all the hard work on creating this. I plan to put up a WordPress blog soon and have a lot to learn about the whole process.
You have done a lot of work to help a lot of people here.
Thanks.
Pingback: WORDPRESSNEWS.COM » WordPress - WordPress.ch - Translate this page
Pingback: JulyBox–ä¸ƒæœˆç›’å » Google Sitemap 生æˆå·¥å…· for wordpress
Pingback: Levysoft » Google rilascia xml sitemap protocol
That’s just amazingly simple and helpful, thank you.
Pingback: Blogger Buster
Great post and very useful information.This plugin is certainly going to help a lot of WordPress bloggers get quicker search engine optimization.
Thanks very much for the info.
Many thanks for Google sitemap. I found this tool very easy and helpful to search sitemaps for blog pages indexed by search engines. I am using the Plugin and it works great. Thanks once again for such kind of plugin.
Sitemaps are a useful tool in helping get your blog pages indexed by search engines, which gives your blog extra “visibility†online. It is good that WordPress users automatically generate Google Sitemaps. Thanks for creating this.
Pingback: Webmasterdays » Blog Archive » Google Sitemaps with Wordpress - Social Patterns
Thanks for you done a great and hard work. Google Sitemaps with WordPress is excellent. It has a good features like it dynamically generate entry for latest post and merge it with a static file containing all previous posts.
HI! Its goods mod, but dont work in my blog (WP @.5.1)???
thanks for the post, got it up and running on a few of my sites. Had heard about this but forgot about it.