function taxonomy_menu_term_count_nodes in Taxonomy menu 7.2
Same name and namespace in other branches
- 8 taxonomy_menu.module \taxonomy_menu_term_count_nodes()
- 7 taxonomy_menu.module \taxonomy_menu_term_count_nodes()
Calculates the number of nodes linked to a term. It can be either recursive and process all the children or just for this very term.
This is inspired by taxonomy_select_nodes from taxonomy.module.
@TODO Make function recursive.
Parameters
$tid: The term ID.
$recursive: Process all the children or not. Default is FALSE according to Drupal standard.
Return value
int The number of nodes attached to a term and optionally its children.
2 calls to taxonomy_menu_term_count_nodes()
- taxonomy_menu_menu_link_prepare in ./
taxonomy_menu.module - Prepares a taxonomy item to be saved as a menu link.
- taxonomy_menu_translated_menu_link_alter in ./
taxonomy_menu.module - Implements hook_translated_menu_link_alter().
File
- ./
taxonomy_menu.module, line 536 - Generates menu links for all selected taxonomy terms.
Code
function taxonomy_menu_term_count_nodes($tid, $recursive = FALSE) {
if ($tid == 0 || !variable_get('taxonomy_maintain_index_table', TRUE)) {
return FALSE;
}
if ($recursive) {
//@TODO Make it recursive.
}
else {
$query = db_select('taxonomy_index', 't');
$query
->condition('tid', $tid);
$query
->addField('t', 'nid');
$query
->addField('t', 'tid');
$count = $query
->countQuery()
->execute()
->fetchField();
}
return $count;
}