Taxonomy/Views related questions: custom "menu" and count of descendant products

aaronp - January 10, 2009 - 19:27

Hey all. I've come across a couple snags that I'm hoping for some help with.

First of all, I'm able to get a count of all children nodes of a term by using taxonomy_get_children() (http://api.drupal.org/api/function/taxonomy_get_children/5), but is there a library function (or some other means) to get a count of all descendants of a term? I have a multi-level taxonomy hierarchy, and, in general, all nodes are tagged with a single term at the deepest level.

Secondly, I have a custom, argument-based view that I've created (products/$arg) that displays all nodes tagged with a term equal to the argument. In one of my block areas, I have a block that outputs all terms in this particular vocabulary and a link to the appropriate page:

<?php
           
// The ID of the taxonomy vocabulary for which you'd like to create a nested list
           
$vid = 1;

           
$depth = 0;
           
$num_at_depth = 0;
           
$tree = taxonomy_get_tree($vid);

            print
"<ul class=\"menu\">\n<li>";
            foreach (
$tree as $term) {
           
$diffdepth=0;
              if (
$term->depth > $depth) {
                print
"\n<ul>\n<li>";
               
$depth = $term->depth;
                   
$num_at_depth = 0;
              }
              if (
$term->depth < $depth) {
               
$diffdepth= $depth -$term->depth;
                while (
$diffdepth > 0){
                    print
"</li>\n</ul>\n";
                   
$diffdepth -- ;
                }
                   
$depth = $term->depth;
              }
              if ((
$term->depth == $depth) && ($num_at_depth > 0)) {
                  print
"</li>\n<li>";
                }
$termPath = strtolower($term->name);
$termPath = str_replace(" ", "-", $termPath); 
              print
l($term->name, 'products/' . $termPath);
               
$num_at_depth ++;
            }
            print
"</li>\n</ul>\n";
?>

Is there any way to get the block to "interact" with the views pages that are created? That is, if someone visits products/term-A (where Term A is a child of Term 1), the menu currently looks like this and does not change for all views:

-Term 1
--Term A
--Term B
--Term C
-Term 2
--Term D
--Term E
-Term 3
--Term F

I'd like the menu to look something like this when someone was on products/term-A, products/term-B, or products/term-1:
-Term 1
--Term A
--Term B
-Term 2
-Term 3

I'm stumped because there isn't really a strong relationship between the view itself and the menu, and I'm not quite sure where to start.

Thoughts?

One shameless bump before I

aaronp - January 12, 2009 - 21:04

One shameless bump before I try other means to find answers.

Maybe I'm not understanding

WorldFallz - January 12, 2009 - 21:17

Maybe I'm not understanding what you're asking for, but isn't this what the http://drupal.org/project/tinytax module does?

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

No; each term links to

aaronp - January 14, 2009 - 18:04

No; each term links to "products/", not the default term pages provided by taxonomy. No need for AJAX in this case, either, unless there's a technical reason that I'm overlooking.

 
 

Drupal is a registered trademark of Dries Buytaert.