tags:

views:

15

answers:

1

I am trying to use hook_nodeapi in my template.php file to alter the breadcrumb. I have tried altering the 'if' statement, but it seems as if Drupal is not even using this hook in my template.php.

function gh_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  $productNodeType = 'product';
  $tid = preg_replace('#[^\d+]#i', '', $_GET['bc']);
  if ($node->type==$productNodeType && $op=='view' && $tid) {
    $breadcrumb[] = l(t('Home'), NULL);
    if ($parents = taxonomy_get_parents_all($tid)) {
      $parents = array_reverse($parents);
      foreach ($parents as $p) {
        $breadcrumb[] = l($p->name, 'taxonomy/term/'. $p->tid);
      }
    }
    drupal_set_breadcrumb($breadcrumb);
  }
}

I found this function (and modified it a bit) from http://stackoverflow.com/questions/1473093/drupal-hierarchical-taxonomical-breadcrumb-trail

+4  A: 

hook functions go in modules, not themes, so that's why your function isn't being called. On a quick skim, it looks like it should work fine if you move it to module. To do that, make a folder in sites/all/modules with a unique module name, e.g. "modulename", make a file named modulename.info like so:

name = Module Name
description = A module to set breadcrumbs on a product.
core = 6.x

And then make a file named modulename.module starting with <?php and then your function. Enable the module, and it should start working.

Scott Reynen
Thanks for the info. I didn't know that hooks couldn't go in a theme. I did get it working by putting the above code in a module. Thanks again!
Rob Decker