You are here

function xmlsitemap_node_priority in XML sitemap 5.2

Same name and namespace in other branches
  1. 5 xmlsitemap_node/xmlsitemap_node.module \xmlsitemap_node_priority()

Calculate the priority of a node.

Parameters

$node: A node object:

Return value

A number between 0 and 1, or -1

2 calls to xmlsitemap_node_priority()
theme_xmlsitemap_node_view_sitemap in xmlsitemap_node/xmlsitemap_node.module
Display the nodes of a view as an XML sitemap.
xmlsitemap_node_xmlsitemap_links in xmlsitemap_node/xmlsitemap_node.module
Implementation of hook_xmlsitemap_links().

File

xmlsitemap_node/xmlsitemap_node.module, line 446
Adds nodes to the sitemap.

Code

function xmlsitemap_node_priority($node) {
  static $maxcomments;
  if (!isset($maxcomments)) {
    $maxcomments = 0;
    if (module_exists('comment')) {
      $maxcomments = db_result(db_query("SELECT MAX(comment_count) FROM {node_comment_statistics}"));
    }
  }
  if (!isset($node->priority_override) || $node->priority_override == -2.0) {
    $priority = 0;
    $priority += variable_get("xmlsitemap_node_type_priority_{$node->type}", 0.5);
    if ($node->promote) {
      $priority += variable_get('xmlsitemap_node_promote_priority', 0.3);
    }
    if (!empty($maxcomments)) {
      $priority += $node->comment_count / $maxcomments * variable_get('xmlsitemap_node_comment_priority', 0.5);
    }
    $priority = round($priority, 1);
    $priority = min($priority, 1);
  }
  else {
    $priority = $node->priority_override;
  }
  return $priority;
}