Topic: sitemap snippet

Hi guys, got another question for you...

I'm using code from the sitemap wiki page here: _http://www.wolfcms.org/wiki/howto:create_a_sitemap to create a sitemap for my site.  I want to have a simple sitemap display on the bottom of all pages, but I'd like to limit it to two levels deep. 

If you take a look at the bottom of the site _http://hardwickvt.org/, you can see that the sitemap is breaking the styling because it is getting too deep with 3 levels.  This is the code I'm using to create the sitemap currently:

<?php
function snippet_sitemap($parent)
{
    $out = '';
    $childs = $parent->children(null,array(),true);
    if (count($childs) > 0)
    {
        $out = '<ul>';        
        foreach ($childs as $child)          
            $out .= '<li>'.$child->link().snippet_sitemap($child).'</li>';        
        $out.= '</ul>';
    }
    return $out;
}
?>

I know I probably just need to make a simple for() loop.  Could someone help me out?

Thanks!

Thumbs up

Re: sitemap snippet

I believe this is what you want? If not, just tweak the number in the first line in the function below.

<?php
function snippet_sitemap($parent)
{
    if ($parent->level() >= 2) return;

    $out = '';
    $childs = $parent->children(null,array(),true);
    if (count($childs) > 0)
    {
        $out = '<ul>';        
        foreach ($childs as $child)          
            $out .= '<li>'.$child->link().snippet_sitemap($child).'</li>';        
        $out.= '</ul>';
    }
    return $out;
}
?>
Wolf CMS founder and lead developer
Please always check the Support forums and Wiki before asking. (My Ohloh account.)
Like Wolf CMS? Consider making a financial contribution.

Re: sitemap snippet

That works great!  Thank you.  I didn't think of doing it that way.

Thumbs up