--- a/taxonomy_menu.module 2012-03-19 07:07:50.000000000 +0100 +++ b/taxonomy_menu.module 2015-05-08 16:48:08.000000000 +0200 @@ -775,17 +775,26 @@ * @param $vid * @return boolean */ -function _taxonomy_menu_children_has_nodes($tid, $vid, $has_nodes = FALSE) { - if (!$has_nodes) { - $children = taxonomy_get_children($tid, $vid); - foreach ($children as $tid => $term) { - if (_taxonomy_menu_term_count($tid) > 0) { - return _taxonomy_menu_children_has_nodes($tid, $vid, TRUE); - } +function _taxonomy_menu_children_has_nodes($tid, $vid) { + $children = taxonomy_get_children($tid, $vid); + + // Try to find nodes in child terms. + foreach ($children as $tid => $term) { + if (_taxonomy_menu_term_count($tid) > 0) { + return TRUE; } } - return $has_nodes; + + // All children have no nodes. Check their descendents. + foreach ($children as $tid => $term) { + if (_taxonomy_menu_children_has_nodes($tid, $vid)) { + return TRUE; + } + } + + return FALSE; } + /** * Helper function for insert and update hooks */ @@ -793,7 +802,12 @@ // if tid is 0 then do not chagne any settings if ($item['tid'] > 0) { // get the number of node attached to this term - $num = _taxonomy_menu_term_count($item['tid']); + if (variable_get('taxonomy_menu_display_descendants_'. $item['vid'], FALSE)) { + $num = taxonomy_term_count_nodes($item['tid']); + } + else { + $num = _taxonomy_menu_term_count($item['tid']); + } // if hide menu is selected and the term count is 0 and the term has no children then do not create the menu item if ($num == 0 &&