Q. How to generate Sitemap ?

Feed 3 posts, 2 voices

Dec 9, 2007 21:06
Avatar
390 posts

create a snippet sitemap with filter set to none and body:

<?php
function snippet_sitemap($parent)
{
    $out = '';
    $childs = $parent->children();
    if (count($childs) > 0)
    {
        $out = '<ul>';
        foreach ($childs as $child)
            $out .= '<li>'.$child->link().snippet_sitemap($child).'</li>';
        $out.= '</ul>';
    }
    return $out;
}
?>
<div id="sitemap">
<?php echo snippet_sitemap($this->find('/')); ?>
</div>

in your sitemap page body, write: <?php $this->includeSnippet('sitemap'); ?> and use your Normal template

note: set your sitemap page hidden if you don't want it in your "sitemap".

 
Dec 10, 2007 07:03
Avatar
964 posts

This is beautiful! :)) Thank you, Philippe!

 
Dec 10, 2007 14:50
Avatar
964 posts

Just added this to the wiki with a bit of light editing.

 
Jan 28, 2008 15:16
Avatar
390 posts

if you want to include hidden pages just change $parent->children() by $parent->children(null, array(), true)