Hi Nancy,

I was looking into the breadcrumb stuff again, related to: http://drupal.org/node/671568 with that I could change the Breadcrumb correctly in /taxonomy/term.

But I have another issue, thats why I start a new issue.

I use hierarchical_select, and this module gives the possibility to add a term and then the parent term is also shown.
But now in the breadcrumb I see the parent itself, and again the parent and subterm.
For instance I see: Home >> Weblinks >> Italy | Italy | Le Marche
So twice I see Italy!

Could you help me to only get the parents shown ones please?

I noticed googling myself that may be it is related to: http://drupal.org/node/217676 (taxonomy_get_parents_all() doesn't work correctly with multiple hierarchy terms).

In this code I saw you used taxonomy_get_parents_all. May be for now better to make a weblinks function, because until now it is not aranged in D6, something like underneath:

/**
 *  Implementation of weblinks_taxonomy_get_parents_all because of bug:http://drupal.org/node/217676
 */
function weblinks_taxonomy_get_parents_all($tid) {
   $parents = array();
   if ($term = taxonomy_term_load($tid)) {
     $parents[] = $term;
     $n = 0;
    while ($n < count($parents)) {
      if ($parent = taxonomy_get_parents($parents[$n]->tid)) {
        $parents = array_merge($parents, $parent);
      }
       $n++;
     }
   }

Thanks a lot in advance for your reply.

Comments

summit’s picture

Hi Nancy,

The proposed function is:

/**
 * Find all ancestors of a given term ID.
 */
function weblinks_taxonomy_get_parents_all($tid) {
  $parents = array();
  if ($term = taxonomy_term_load($tid)) {
    $parents[] = $term;
    $n = 0;
    while ($n < count($parents)) {
	   if ($parent = taxonomy_get_parents($parents[$n]->tid)) {
       $parents = array_merge($parents, $parent);
      }
      $n++;
    }
  }
  return $parents;
}

Unfortunately it can't work like this in D6..because of non existing taxonomy_term_load.

summit’s picture

I tried it with taxonomy_get_term (ancestor of taxonomy_term_load..) but still I got:
Home >> Weblinks >> Italy | Italy | La Marche

See function:

function weblinks_taxonomy_get_parents_all($tid) {
  $parents = array();
  if ($term = taxonomy_get_term($tid)) {
    $parents[] = $term;
    $n = 0;
    while ($n < count($parents)) {
	   if ($parent = taxonomy_get_parents($parents[$n]->tid)) {
       $parents = array_merge($parents, $parent);
      }
      $n++;
    }
  }
  return $parents;
}
summit’s picture

Hi Nancy with function function weblinks_view this is still not working!

Could you help me please to get this working.
You said Unfortunately it can't work like this in D6..because of non existing taxonomy_term_load.
Is this may now solveble, does anybody know how to deal with this?

greetings, Martijn

Code function:

/**
 * Implementation of hook_view().
 * This formats a viewable link node.
 */
function weblinks_view(&$node, $teaser = FALSE, $page = FALSE) {
  if ($page) {
    // Breadcrumb navigation
    $breadcrumb = array();
    $breadcrumb[] = l(t('Home'), '<front>');

    // See the comments in hook_init.
    $breadcrumb[] = l(_weblinks_get_menu_title(), 'weblinks');

    if (isset($node->taxonomy)) {
      $tids = array_keys($node->taxonomy);
      $parent_links = array();
      foreach ($tids as $tid) {
        if ($parents = taxonomy_get_parents_all($tid)) {
          $parents = array_reverse($parents);
          foreach ($parents as $p) {
            $parent_links[] = l($p->name, 'taxonomy/term/'. $p->tid);
          }
        }
      }
      $breadcrumb[] = implode(' | ', $parent_links);
    }
    drupal_set_breadcrumb($breadcrumb);
  }
  $node->is_teaser = $teaser;
  $node->content['body']['#value'] = theme('weblinks_link', $node, $teaser);
  return $node;
}
summit’s picture

Hi Nancy,

I saw there is a helper module: http://drupal.org/project/taxidermy in which there is the function:
taxidermy_taxonomy_term_load.

/*
 * Implementation of hook_taxonomy_term_load.
 */
function taxidermy_taxonomy_term_load(&$term) {
  $term->parent = array_map('_taxonomy_get_tid_from_term', taxonomy_get_parents($term->tid));
  $term->related = array_map('_taxonomy_get_tid_from_term', taxonomy_get_related($term->tid));
  $term->synonyms = implode("\n", taxonomy_get_synonyms($term->tid));
}

Would it be helpful to use this helper-module related to breadcrumb weblinks drupal 6?

greetings,
Martijn

Padmakani’s picture

function yourthemename_breadcrumb( $variables )
{
// init
$breadcrumb = $variables['breadcrumb'];

// taxonomy hierarchy
$hierarchy = array();
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)))
{
$tid = (int)arg(2);
$parents = taxonomy_get_parents_all($tid);
$parents = array_reverse($parents);
$breadcrumb = array();
$breadcrumb[] = l('Home', '/');
foreach( $parents as $k=>$v)
{
$breadcrumb[] = l($v->name, 'taxonomy/term/'. $v->tid);;
}
}

// rendering
if (!empty($breadcrumb))
{
$output = '

' . t('You are here') . '

';
$output .= '

';
return $output;
}

}

GStegemann’s picture

Hi Nancy,

is this issue still relevant?

nancydru’s picture

I don't know, but probably.

summit’s picture

Hi,
If the code is unchanged..yes then it is still relevant!
Greetings, Martijn

GStegemann’s picture

OK. But the the strange thing is I cannot reproduce it.

On my test site the breadcrumb looks correct:

Home » Web Links » Automatisierungstechnik | FactoryLink

Nothing is displayed twice. In what theme do you see the duplicates?

summit’s picture

Hi,

So this problem is not on your site then: https://drupal.org/node/217676
I have very old code..maybe when I update all modules to latest versions, it isn;t happening anymore.
Unfortunately I do not have time for this on this particular site where this problem occurred..(my post is almost 4 years old where it occured..)
We are talking about Drupal 6 still yes?

Greetings, Martijn

GStegemann’s picture

No, I don't see the problem. Yes, we are talking about Drupal 6. My test site is running under Drupal core 6.30 with up-to-date modules.

Gerhard