summaryrefslogtreecommitdiff
path: root/modules/taxonomy
diff options
context:
space:
mode:
Diffstat (limited to 'modules/taxonomy')
-rw-r--r--modules/taxonomy/taxonomy.module15
1 files changed, 9 insertions, 6 deletions
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 99b3460f9..cb425eb53 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -462,7 +462,7 @@ function taxonomy_get_children($tid, $vid = 0, $key = "tid") {
}
// hierarchy: get whole family, with tid, parent and depth; useful to show
-function taxonomy_get_tree($vocabulary_id, $parent = 0, $depth = -1, $key = "tid") {
+function taxonomy_get_tree($vocabulary_id, $parent = 0, $depth = -1, $max_depth = NULL) {
static $children, $parents, $terms;
$depth++;
@@ -479,14 +479,17 @@ function taxonomy_get_tree($vocabulary_id, $parent = 0, $depth = -1, $key = "tid
}
}
+ $max_depth = ($max_depth == '') ? count($children[$vocabulary_id]) : $max_depth;
if ($children[$vocabulary_id][$parent]) {
foreach ($children[$vocabulary_id][$parent] as $child) {
- $terms[$vocabulary_id][$child]->depth = $depth;
- unset($terms[$vocabulary_id][$child]->parent); // this is not useful as it would show one parent only
- $terms[$vocabulary_id][$child]->parents = $parents[$vocabulary_id][$child];
- $tree[] = $terms[$vocabulary_id][$child];
+ if ($max_depth > $depth) {
+ $terms[$vocabulary_id][$child]->depth = $depth;
+ unset($terms[$vocabulary_id][$child]->parent); // this is not useful as it would show one parent only
+ $terms[$vocabulary_id][$child]->parents = $parents[$vocabulary_id][$child];
+ $tree[] = $terms[$vocabulary_id][$child];
- $tree = array_merge($tree, taxonomy_get_tree($vocabulary_id, $child, $depth));
+ $tree = array_merge($tree, taxonomy_get_tree($vocabulary_id, $child, $depth, $max_depth));
+ }
}
}