Getting a breadcrumb for a node
When you need the breadcrumb for a node in Drupal, there’s no straightforward way to get them. I needed this because I was using the Node Images module, but wanted to display (some of) the images as a page. Using some trickery, I got the image to display as a node/page, but didn’t have a breadcrumb.
Here’s how I solved it:
// optional, load the node
$node = node_load($nid);
// 'render' the node, but discard the result
node_view($node, FALSE, TRUE);
// breadcrumb manipulation
$crumbs = drupal_get_breadcrumb();
$crumbs[] = l($node->title, $node->path);
drupal_set_breadcrumb($crumbs);
Of course, this has a certain impact on performance: the “parent” node is rendered, but the result is discarded (as we don’t need it). This also sets the breadcrumb for the node. We then retrieve it, and append the node’s info to it. After that, we set that breadcrumb to be the breadcrumb for the current page.
AFAIK, there’s no better way to do this (in drupal 5.x, at least). I was also using Custom Breadcrumbs, so I needed the full works to get the actual breadcrumb. It’s maybe not the most elegant and most performant solution, but it works.