Add links programmatically to xmlsitemap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_cron(). | |
*/ | |
function MYMODULE_cron() { | |
MYMODULE_xmlsitemap_links(); | |
} | |
/** | |
* Implements hook_xmlsitemap_links | |
*/ | |
function MYMODULE_xmlsitemap_links() { | |
$menu_links = menu_load_links("main-menu"); | |
$sorted = array(); | |
foreach ($menu_links as $menu_link) { | |
if ($menu_link['link_path'] == '<view>' || $menu_link['hidden'] == 1) { continue; } | |
$absolute_weight = $menu_link['weight']; | |
if ($absolute_weight < 0) { $absolute_weight += 100; } | |
if ($menu_link['depth'] > 1) { $absolute_weight = (($menu_link['depth'] - 1) * 10) + $absolute_weight; } | |
$sorted[$absolute_weight] = array( | |
'type' => 'MYMODULE', | |
'id' => $menu_link['mlid'], | |
'loc' => $menu_link['link_path'], | |
'lastmod' => time(), | |
'changefreq' => 4600, | |
'priority' => 0.5, | |
); | |
} | |
ksort($sorted); | |
$links = array_values($sorted); | |
foreach ($links as $link) { | |
xmlsitemap_link_save($link); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great !!! Thanks