How to list all nodes with children taxonomy terms from certain parent? Enabled default taxonomy view with depth modifier, but it doesn't seem to work..

Comments

ytsurk’s picture

  • taxonomy_get_tree()
  • taxonomy_term_load()

and play with them in a block or page

aha - interesting ..

newindrupal’s picture

Thanks! But can you be more specific on how/where to use them?

ytsurk’s picture

<?php
if ($terms = taxonomy_get_tree(1, 0, 1)) {
        foreach (
$terms as $term) {
          
/* $obj = taxonomy_term_load($term->tid); */

$build = '<h1>'.$term->name.'</h1><p>'.$term->description.'</p>';

$arrayAttrs = array();
$arrayAttrs['class'] = 'myStyle';

print

l($build, 'taxonomy/term/'.$term->tid), array('html' => true, 'attributes' => $arrayAttrs));
        }
      }
?>

where the third param of http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.module/func... is depth

.. this code never hit a compiler ;)

edit: put that in a new block - with php as text format

aha - interesting ..

Scott J’s picture

Parse error: syntax error, unexpected ',' in /modules/php/php.module(75) : eval()'d code on line 11

ytsurk’s picture

there was a closing braket too much ..

<?php
if ($terms = taxonomy_get_tree(1, 0, 1)) {
        foreach (
$terms as $term) {
          
/* $obj = taxonomy_term_load($term->tid); */

$build = '<h1>'.$term->name.'</h1><p>'.$term->description.'</p>';

$arrayAttrs = array();
$arrayAttrs['class'] = 'myStyle';

print

l($build, 'taxonomy/term/'.$term->tid, array('html' => true, 'attributes' => $arrayAttrs));
        }
      }
?>

aha - interesting ..

alexbk66-’s picture

@ytsurk, thank you for the code!

I wonder now how can I get the $vid and $parent arguments for taxonomy_get_tree from the current node?

My content type has a single selection hierarchical vocabulary associated with it. So I want a block which lists all children of the term associated with the currently displayed node.

ytsurk’s picture

<?php
$vid
= 3;
if (
$terms = taxonomy_get_tree($vid, 0, 1)) {
   ...
}
?>

should do it ..,
to have it dynamically there are several ways,
for D7 look @ DBTNG

aha - interesting ..

alexbk66-’s picture

@ytsurk, you probably misunderstood my question.

Let say I'm displaying a node, i.e. blog post, it has a single tag. I want to create a block which will display all children of the term associated with the current post. So the question is - how can I get this term id from the current node?

ytsurk’s picture

never did that, but you probably need to call this method
taxonomy_select_nodes

you'll find the termId in your nodeObject ..

aha - interesting ..