Hi,
Looking through drupal.org, and can't find my answer. What I would like is having a list of combined taxonomy terms list of all terms hierarchical in my different vocabularies.

I) I have a vocabulary: regional with
-holland
---coast provinces
-------amsterdam
II) I have a vocabulary: camping sorts
-kidscamping
-nature-camping
etc..
III) and I have a vocabulary: specialities
-swimmingpool
-restaurant
etc..

IV) I have a page/panel on which I show different panes. The name of the panel is over
So what I would like is be able to build a html list as a sort of sitemap, with all these factors combined.

Combining above the url's in this list should be having all combination of above vocabularies:

over/holland/kidscamping/swimmingpool
over/holland/kidscamping/restaurant
..
..
over/holland/coast provinces/amsterdam/naturecamping/swimmingpool
over/holland/coast provinces/amsterdam/naturecamping/restaurant
etc..

Can anyone help me with a snippet? I think it is an add on to: http://drupal.org/node/121662#comment-1861742.

Thanks a lot in advance
greetings,
Martijn

Comments

Summit’s picture

Hi,
I tried something like underneath, but it doesn't work. The combining in arrays somehow needs other code I think..

<?php
//First vocabulary regional
$vid1 = 4;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
//Second vocabulary camping sorts
$vid2 = 2; 
$items1 = array();
$items2 = array();
$terms1 = taxonomy_get_tree($vid1);
$terms2 = taxonomy_get_tree($vid2);
//first foreach loop to get the terms from first vocabulary
foreach ( $terms1 as $term1 ) { 
    $count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term1->tid)); 
    $items1[] = l($term1->name, "over/$term1->name") ;
}
//second foreach loop to get the terms from second vocabulary
foreach ( $terms2 as $term2 ) { 
    $count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term2->tid)); 
    $items2[] = l($term2->name, "$term2->name") ;
}

//Trying to combine the output to get both term names in the url..nbot working yet..
$items_combined = $items1  + $items2;
if ( count($items1) ) {  print theme('item_list', $items_combined);}
?>

Thanks for helping me in advance!
greetings,
Martijn

Summit’s picture

Hi,

I have something working using underneath..but may be somebody knows a better way?

<?php
//First vocabulary regional
$vid1 = 4;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
//Second vocabulary camping sorts
$vid2 = 2;
$items = array();
$terms1 = taxonomy_get_tree($vid1);
$terms2 = taxonomy_get_tree($vid2);
//first foreach loop to get the terms from first vocabulary
foreach ( $terms1 as $term1 ) {
    $count1 = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term1->tid));
    //second foreach loop to get the terms from second vocabulary
    foreach ( $terms2 as $term2 ) {
        $count2 = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term2->tid));

        //Trying to combine the output to get both term names in the url..not working yet..
        $items[] = l($term1->name . '-' . $term2->name, "over/$term1->name/$term2->name") ;
    }
}

if ( count($items) ) {  print theme('item_list', $items);}
?>
Summit’s picture

But this is a very resourceful query...See underneath code for 3 vocabularies.
May be somebody can help getting a less resourcefull query working?

<?php
//First vocabulary regional
$vid1 = 4;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
//Second vocabulary camping sorts
$vid2 = 2;
//Third vocabulary specialities
$vid3 = 6;
$items = array();
$terms1 = taxonomy_get_tree($vid1);
$terms2 = taxonomy_get_tree($vid2);
$terms3 = taxonomy_get_tree($vid3);
//first foreach loop to get the terms from first vocabulary
foreach ( $terms1 as $term1 ) {
    $count1 = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term1->tid));
    //second foreach loop to get the terms from second vocabulary
    foreach ( $terms2 as $term2 ) {
        $count2 = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term2->tid));
        //third foreach loop to get the terms from the third vocabulary
         foreach ( $terms3 as $term3 ) {
        $count3 = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term3->tid));

        //Trying to combine the output to get all three term names in the url
        $items[] = l($term1->name . '-' . $term2->name.  '-' . $term3->name,"over/$term1->name/$term2->name/$term3->name") ;
        }
    }
}

if ( count($items) ) {  print theme('item_list', $items);}
?>
Summit’s picture

Hi,

Does anybody know how in above example I can not print the 3th level of depth please?
I want to show the country and region level, but not yet the places level.

EDIT: I did it myself with underneath code!

<?php
//First vocabulary regional
$vid1 = 4;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
//Second vocabulary camping sorts
$vid2 = 2;
//Third vocabulary specialities
$vid3 = 6;
$items = array();
$terms1 = taxonomy_get_tree($vid1);
$terms2 = taxonomy_get_tree($vid2);
$terms3 = taxonomy_get_tree($vid3);
//first foreach loop to get the terms from first vocabulary
foreach ( $terms1 as $term1 ) {
    $count1 = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term1->tid));
    //second foreach loop to get the terms from second vocabulary
    foreach ( $terms2 as $term2 ) {
        $count2 = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term2->tid));
        //third foreach loop to get the terms from the third vocabulary
         foreach ( $terms3 as $term3 ) {
          $count3 = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term3->tid));
      
          //Trying to combine the output to get all three term names in the url
          //Only show terms of depth above 2.
          if ($term1-> depth <= 1) { 
            $items[] = l($term1->name . '-' . $term2->name.  '-' . $term3->name,"over/$term1->name/$term2->name/$term3->name") ;
          }
        }
    }
}

if ( count($items) ) {  print theme('item_list', $items);}
?>

thanks a lot in advance for your reply!

greetings,
Martijn