Creating an XML sitemap with PHP
- by iMaster
I'm trying to create a sitemap that will automatically update. I've done something similiar with my RSS feed, but this sitemap refuses to work. You can view it live at http://designdeluge.com/sitemap.xml I think the main problem is that its not recognizing the PHP code. Here's the full source:
<?php header('Content-type: text/xml'); ?>
<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
<url>
<loc>http://www.designdeluge.com/</loc>
<lastmod>2010-04-29</lastmod>
<changefreq>daily</changefreq>
<priority>1.00</priority>
</url>
<url>
<loc>http://www.designdeluge.com/archives</loc>
<lastmod>2010-04-29</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>http://www.designdeluge.com/about.php</loc>
<lastmod>2010-04-29</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<?php
include 'connection.php';
$entries = mysql_query("SELECT * FROM Entries ORDER BY timestamp DESC");
while($row = mysql_fetch_array($entries)) {
$title = stripslashes($row['title']);
$date = date("Y-m-d", strtotime($row['timestamp']));
?>
<url>
<loc>http://www.designdeluge.com/<?php echo $row['title']; ?></loc>
<lastmod><?php echo $date; ?></lastmod>
<changefreq>none</changefreq>
<priority>0.5</priority>
</url>
<?php
}
?>
</urlset>
The problem is that the dynamic URL's (e.g. the ones pulled from the DB) aren't being generated and the sitemap won't validate. Thanks!