I am creating a web application using php. I want to create a sitemap for my application. I dont know how to create that xml file and how to include in php. And also I want to know that, is it possible to check that in my localhost before upload into my hosting server? I want a simple example code to create the sitemap.xml file and how to link that in php page? Please, does any one can help me?

Recommended Answers

All 3 Replies

If your pages are stored in the database, then you can generate your sitemap easily from a query. It depends on how your website is built.

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc>http://mysite.com/</loc>
        <lastmod>2012-09-16</lastmod>
        <changefreq>Weekly</changefreq>
        <priority>0.9</priority>
    </url>
    <url>
        <loc>http://mysite.com/about.php</loc>
        <lastmod>2012-09-16</lastmod>
        <changefreq>Weekly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>http://mysite.com/something.php</loc>
        <lastmod>2012-09-16</lastmod>
        <changefreq>Daily</changefreq>
        <priority>0.7</priority>
    </url>
    <url>
        <loc>http://mysite.com/contact.php</loc>
        <lastmod>2012-09-16</lastmod>
        <changefreq>Monthly</changefreq>
        <priority>0.6</priority>
    </url>
</urlset>

not sure what youre trying to test locally but your sitemap don't mean much on a local server so you can open it and check for errors but thats about it. you can hardcode the sitemap in your php or convert the sitemap using regex but thats a pain in the ass. I think there are frameworks that can handle that but your better of hardcoding it in an unordered list

thank you! I got the required result

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.