views:

67

answers:

3

I want create sitemap but I know very litle about sitemap. I use cakephp. There has a lot software on google guide but i still want ask anyway easy create sitemap for cakephp.

I uploaded website on server, it dont lie on localhost

+1  A: 

Here's a quick'n'dirty example for you to play with and adjust to your needs:

In your controller:

function sitemap()
{
    Configure::write('debug', 0);

    $articles = $this->Article->getSitemapInformation();

    $this->set(compact('articles'));
    $this->RequestHandler->respondAs('xml');
}

Your "Article" model:

function getSitemapInformation()
{
    return $this->find('all', array(/* your query here */));
}

View:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&gt;
    <?php foreach ($articles as $article): ?>
    <url>
        <loc><?php echo Router::url(/* generate the URLs here */); ?></loc>
        <lastmod><?php echo $time->toAtom(/* last update time here */); ?></lastmod>
        <changefreq>weekly</changefreq>
    </url>
    <?php endforeach; ?>
</urlset>
dr Hannibal Lecter
thanks for examples
meotimdihia
A: 

that is a good start, now just add

Router::parseExtentions('xml'); to routes.php

from there you want to have a route like

Router::connect('/sitemap', array('controller' => 'posts' ....., 'ext' => 'xml')) that will direct site.com/sitemap.xml to the controller/action where the sitemap is.

create a xml layout with the correct headings, and move the view file to views/posts/xml/file.ctp

dogmatic69
thanks a lot comment
meotimdihia
A: 

Simpler way would be to create sitemap using available too like Sitemap Creation Tool