I am trying to print out the values within a hierarchical select'ed taxonomy via custom php print statements in a node-.tpl.php and using values from dsm()

I have entered print statements along "print $node->taxonomy[**]-->name" and it worked for only individual cases because each term is stored in a different array ("**"). This is weird and clunky. Is this a bug or is this the issue discussed in the readme section?

My taxonomy vocabulary had three terms state->city->county so in essence only three arrays should be used. I believe HS is creating arrays for each term. I would like to have one generic print statement that would print the correct values based on each unique node.

How can I programatically print values? Be advised I am no PHP whiz.

Comments

Stomper’s picture

Anyone with experience with printing content from a hierarchical select enabled taxonomy on a custom .tpl via PHP print statement?

Thanks

Stomper’s picture

I made some progress after reading the included README. It provides code to print the lineage, but I am looking to be able to print each term separately from the lineage.

Current output using the README code is:
Location: state>county>city

I would like to print:

State: state
County: county
City: city

How can I do this with my node.tpl.php
_________________________
from README::

Sample usage (using Taxonomy and Hierarchical Select Taxonomy):

 if ($taxonomy):
    require_once(drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc');
    $vid = 2;                                                    // Vocabulary ID. CHANGE THIS!
    $config_id = "taxonomy-$vid";                                // Generate the config ID.
    $config = hierarchical_select_common_config_get($config_id); // Get the Hierarchical Select configuration through the config ID.
    $config['module'] = 'hs_taxonomy';                           // Set the module.
    $config['params']['vid'] = $vid;                             // Set the parameters.
  
print theme('hierarchical_select_selection_as_lineages', $node->taxonomy, $config);

endif;
______________________

Stomper’s picture

Someone must've attempted to print individual terms from a lineage, how did you do it?

Stomper’s picture

Tips appreciated, I am just trying to print individual terms from a lineage on a node-.tpl.php. The readme instructs on printing entire lineages, I'd like to break down the lineage into parent-child etc, and print them separately.

virtualdrupal’s picture

This might require some adjusting and isn't as clean as you were looking at doing, but hopefully it helps

// START Fully Themed taxonomy list with nested children- place in template.php 
function private_get_taxparent($vocabid, $father = 0) {
    $pieces = array();
	global $idvar;
	$idvar = 1;
    $theterms = taxonomy_get_tree($vocabid, $father, -1, 1);
    foreach ( $theterms as $theterm ) {
        $count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $theterm->tid));
        $pieces[] =  l($theterm->name, "taxonomy/term/$theterm->tid") . " ($count)" . private_get_taxchild($vocabid, $theterm->tid);
		$idvar = $idvar + 1;
    }
    if ( count($pieces) ) {
	$idvar = 1;
	$output = "<div id='" . $idvar . "' class='parent-list'>";	
    $output .= "<ul class='parent'>";
    $num_items = count($pieces);
    foreach ($pieces as $i => $piece) {
      $attributes = array();
      $children = array();
      if (is_array($piece)) {
        foreach ($piece as $key => $value) {
          if ($key == 'data') {
            $data = $value;
          }
          elseif ($key == 'children') {
            $children = $value;
          }
          else {
            $attributes[$key] = $value;
          }
        }
      }
      else {
        $data = $piece;
      }
      if (count($children) > 0) {
        $data .= "arrrr"; // doesn't work?
      }
      if ($i == 0) {
        $attributes['class'] = empty($attributes['class']) ? 'first' : ($attributes['class'] .' first');
      }
      if ($i == $num_items - 1) {
        $attributes['class'] = empty($attributes['class']) ? 'last' : ($attributes['class'] .' last');
      }
      $output .= "<li id='". $idvar . "' " . drupal_attributes($attributes) .">". $data ."</li>\n";
	  $idvar = $idvar + 1;
    }
    $output .= "</ul>";
    $output .= "</div>";	
    }
	return $output;
}
	
function private_get_taxchild($vocabid, $father = 0) {
    $pieces = array();
	global $idvar;
    $theterms = taxonomy_get_tree($vocabid, $father, -1, 1);
    foreach ( $theterms as $theterm ) {
        $count = db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $theterm->tid));
        $pieces[] =  l($theterm->name, "taxonomy/term/$theterm->tid") . " ($count)" . private_get_taxchild($vocabid, $theterm->tid);
    }
    if ( count($pieces) ) {
	$output = "<div id='" . $idvar . "' class='child-list'>";	
    $output .= "<ul class='child'>";
    $num_items = count($pieces);
    foreach ($pieces as $i => $piece) {
      $attributes = array();
      $children = array();
      if (is_array($piece)) {
        foreach ($piece as $key => $value) {
          if ($key == 'data') {
            $data = $value;
          }
          elseif ($key == 'children') {
            $children = $value;
          }
          else {
            $attributes[$key] = $value;
          }
        }
      }
      else {
        $data = $piece;
      }
      if (count($children) > 0) {
        $data .= "arrrr"; // doesn't work?
      }
      if ($i == 0) {
        $attributes['class'] = empty($attributes['class']) ? 'first' : ($attributes['class'] .' first');
      }
      if ($i == $num_items - 1) {
        $attributes['class'] = empty($attributes['class']) ? 'last' : ($attributes['class'] .' last');
      }
      $output .= "<li". drupal_attributes($attributes) .">". $data ."</li>\n";
    }
    $output .= "</ul>";
    $output .= "</div>";	
    }
	return $output;
}

// Called in theme with vocabulary id

print private_get_taxparent('3');
virtualdrupal’s picture

I've only used it two terms deep though, so it may need adjusting if you're doing 3

stefan.r’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

6.x issue without activity for over 3 years, closing.

Please reopen if this is still an issue in 7.x.