Creating an XML sitemap with PHP

Posted by iMaster on Stack Overflow See other posts from Stack Overflow or by iMaster
Published on 2010-04-30T21:27:08Z Indexed on 2010/04/30 21:37 UTC
Read the original article Hit count: 430

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about php

Related posts about sitemap