Tuesday, October 29, 2013

Create a GetSimple sitemap with return_i18n_menu_data function from I18N plugin

A custom sitemap can be easily generated using return_i18n_menu_data() function from I18N GetSimple plugin.

A "sidebar" component below generates a simple sitemap of a site built with GetSimple.

<h2>Sitemap</h2>

<?
$data = return_i18n_menu_data(null, 0, 99, I18N_FILTER_NONE | I18N_OUTPUT_TITLE);

foreach ($data as $item)
{
    echoItem($item, 0, '');
}

function echoItem($item, $level, $path)
{
    $offset = $level * 16;
    $title = $item['title'];
    $url = $item['url'];
    
    $path = getSiteUrl() . $path . $url;

    echo "<li style=\"margin-left: {$offset}px;\"><a href=\"$path\">$title</a></li>\r\n";

    foreach ($item['children'] as $child)
    {
        echoItem($child, $level + 1, $url . '/');
    }
}

function getSiteUrl()
{
    global $SITEURL;
    return parse_url($SITEURL, PHP_URL_PATH);
}
?>

No comments:

Post a Comment