3

Creating collapsible, hierarchical or nested taxonomy list with deepest term linking

http://drupal.org

Here is my initial pass at creating a nested and collapsible list of taxonomy terms. The code makes the deepest term in the nesting a link to the term page.

i started with a node template file ('node-page.tpl.php') so i can wrap it and then make a menu item to it. Inside 'node-page.tpl.php' exists the following code:

<?php
// $title of course is just the value entered in the title field for the designated node.
switch ($title) {
case 'My Taxonomy Categories':
// $vid = the ID of taxonomy vocabulary to create collapsible hierarchical lists
$vid = 1;
$tree = taxonomy_get_tree($vid);
if ($tree) {
drupal_add_js('misc/collapse.js');
$total_terms = count($tree);
foreach ($tree as $key => $term) {
$depth = $term->depth;
if ($key == 0) { // first term
if ($total_terms == 1) {
print ('

  • ' . l($tree[$key]->name, 'taxonomy/term/' . $tree[$key]->tid) . '

');
}
} else { // all terms except first
if ($depth > $last_depth) { // previous term is a parent
print ('' . $tree[$key-1]->name . '');
if ($depth >= $tree[$key+1]->depth) {
print ('

    ');

read more

Read »
Created by emmajane 2 years 28 weeks ago
Category: News   Tags:

PSD to Drupal Theme

Drupal Development

Module Development

Get an Estimate

Tags for Creating collapsible, hierarchical or nested taxonomy list with deepest term linking

Recent comments