function hook_xmlsitemap_links in XML sitemap 5
Define additional links to add to the site map.
This hook allows modules to add additional links to the site map. Links may be associated with nodes, terms, or users, as shown in the example.
Parameters
$type:: If set, a string specifying the type of additional links to return. You can use your own type or a type from one of the included modules:
- node: Links associated with nodes
- term: Links associated with terms
- user: Links associated with users
- xml: An XML site map (for including site maps from other modules)
You can define additional types by adding them to the switch statement.
$excludes:: Depends on the type of links being requested.
- For "node", an array of excluded node types
- For "term", an array of excluded vocabularies
- For "user", an array of included roles
Return value
If $type is xml, return an XML site map. Otherwise, return an array of links or an empty array. Each link should be an array with the following keys:
- nid, tid, uid, or custom ID type: ID to associate with this link (If you have defined your own link type, use the ID key to group related links together.)
- #loc: The URL of the page
- #lastmod: Timestamp of last modification
- #changefreq: Number of seconds between changes
- #priority: A number between 0 and 1 indicating the link's priority
Related topics
4 functions implement hook_xmlsitemap_links()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- xmlsitemap_node_xmlsitemap_links in xmlsitemap_node/
xmlsitemap_node.module - Implementation of hook_xmlsitemap_links().
- xmlsitemap_term_xmlsitemap_links in xmlsitemap_term/
xmlsitemap_term.module - Implementation of hook_xmlsitemap_links().
- xmlsitemap_user_xmlsitemap_links in xmlsitemap_user/
xmlsitemap_user.module - Implementation of hook_xmlsitemap_links().
- xmlsitemap_xmlsitemap_links in ./
xmlsitemap.module - Implementation of hook_xmlsitemap_links().
5 invocations of hook_xmlsitemap_links()
- xmlsitemap_node_xmlsitemap_links in xmlsitemap_node/
xmlsitemap_node.module - Implementation of hook_xmlsitemap_links().
- xmlsitemap_term_xmlsitemap_links in xmlsitemap_term/
xmlsitemap_term.module - Implementation of hook_xmlsitemap_links().
- xmlsitemap_user_xmlsitemap_links in xmlsitemap_user/
xmlsitemap_user.module - Implementation of hook_xmlsitemap_links().
- _xmlsitemap_links in ./
xmlsitemap.module - Get all site map links.
- _xmlsitemap_xml_links in ./
xmlsitemap.module - Extract links from site maps returned by hook_xmlsitemap_links().
File
- docs/
xmlsitemap.php, line 56 - XML Sitemap API documentation
Code
function hook_xmlsitemap_links($type = NULL, $excludes = array()) {
$links = array();
switch ($type) {
case 'node':
break;
case 'term':
break;
case 'user':
// Load profiles.
$result = db_query("\n SELECT u.uid, xu.last_changed, xu.previously_changed, xu.priority_override, SUM(xur.priority), ua.dst AS alias\n FROM {users} u\n LEFT JOIN {users_roles} ur ON ur.uid = u.uid\n LEFT JOIN {xmlsitemap_user_role} xur ON xur.rid = ur.rid\n LEFT JOIN {xmlsitemap_user} xu ON xu.uid = u.uid\n LEFT JOIN {url_alias} ua ON ua.pid = xu.pid\n WHERE (xu.priority_override IS NULL OR xu.priority_override >= 0) AND u.uid <> %d\n GROUP BY u.uid, xu.last_changed, xu.previously_changed, xu.priority_override, ua.dst\n HAVING MIN(xur.priority) <> -1\n ", _xmlsitemap_user_frontpage());
// Create link array for each profile.
while ($user = db_fetch_object($result)) {
$age = time() - $user->last_changed;
$interval = empty($user->previously_changed) ? 0 : $user->last_changed - $user->previously_changed;
$links[] = array(
'uid' => $user->uid,
'#loc' => xmlsitemap_url("user/{$user->uid}", $user->alias, NULL, NULL, TRUE),
'#lastmod' => $user->last_changed,
'#changefreq' => max($age, $interval),
'#priority' => _xmlsitemap_user_priority($user),
);
}
// Add other user links to the links array.
$links = array_merge($links, module_invoke_all('xmlsitemap_links', 'user'));
// Sort links by user ID and URL.
foreach ($links as $key => $link) {
$uid[$key] = $link['uid'];
$loc[$key] = $link['#loc'];
}
array_multisort($uid, $loc, $links);
break;
case 'xml':
// Retrieve an XML site map.
$links = example_sitemap();
break;
default:
// Add arbitrary additional links.
$result = db_query("\n SELECT xa.*, ua.dst AS alias FROM {xmlsitemap_additional} xa\n LEFT JOIN {url_alias} ua ON xa.pid = ua.pid\n ");
while ($link = db_fetch_object($result)) {
$age = time() - $link->last_changed;
if (!empty($link->previously_changed)) {
$interval = $link->last_changed - $link->previously_changed;
}
else {
$interval = 0;
}
$entry = array(
'#loc' => xmlsitemap_url($link->path, $link->alias, NULL, NULL, TRUE),
'#lastmod' => $link->last_changed,
'#changefreq' => max($age, $interval),
'#priority' => $link->priority,
);
$additional[] = $entry;
}
break;
}
return $links;
}