sixohthree.com

Google Sitemaps and WordPress 2.0

I’ve created a script to dump my blog post history into an XML file suitable for Google Sitemaps. Note that I consider any XML-building script that does not use XML creation tools to be a hack. This is a hack.

<?php

header("Content-type: application/xml");
require_once( dirname(__FILE__) . '/wp-config.php'); // get the wordpress functions

// sitemap header
echo '<'.'?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">';

// set upper limit to a sufficiently high number
$posts = get_posts('numberposts=32767&order=ASC&orderby=post_date');

// output all the posts
foreach($posts as $post): setup_postdata($post);
?>
    <url>
        <loc><?php the_permalink(); ?></loc>
        <lastmod><?php echo get_post_modified_time('Y-m-d') ?></lastmod>
    </url>
<?php

endforeach;
echo '</urlset>';

?>

Example: sitemap.php.

I also add a rewrite condition to my .htaccess file:

RewriteRule ^sitemap.xml$ sitemap.php [L]

Thus is born sitemap.xml.

Posted 2006-03-30 at 17:06
Categories Blogging
Tags
Short URL http://sixohthree.com/364
Canonical URL http://sixohthree.com/364/sitemaps

Respond

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>