You are here

function xmlsitemap_taxonomy_get_term_depth in XML sitemap 6.2

Same name and namespace in other branches
  1. 7.2 xmlsitemap_taxonomy/xmlsitemap_taxonomy.module \xmlsitemap_taxonomy_get_term_depth()

Find the tree depth of a taxonomy term.

Parameters

$term: A taxonomy term object.

Return value

The tree depth of the term.

File

xmlsitemap_taxonomy/xmlsitemap_taxonomy.module, line 190

Code

function xmlsitemap_taxonomy_get_term_depth(stdClass $term) {
  static $depths = array();
  if (!isset($depths[$term->tid])) {
    if ($parent = db_result(db_query("SELECT parent FROM {term_hierarchy} WHERE tid = %d", $term->tid))) {

      // If the term has a parent, the term's depth is the parent's depth + 1.
      if (!isset($depths[$parent])) {
        $depths[$parent] = xmlsitemap_taxonomy_get_term_depth($parent);
      }
      $depths[$term->tid] = $depths[$parent] + 1;
    }
    else {

      // Term has no parents, so depth is 0.
      $depths[$term->tid] = 0;
    }
  }
  return $depths[$term->tid];
}