Custom Breadcrumbs: Customizing the breadcrumb trail

Last modified: April 14, 2008 - 14:14

As the name suggests, Custom Breadcrumbs allows you to create and modify your own breadcrumbs based on node type. After enabling the module, go to Administer > Site building > Custom breadcrumbs. On this page you'll see the option to add a new custom breadcrumb.

Clicking on that link, you have the option to select the node type the breadcrumb will apply to.
There are two text fields below: "Titles" and "Paths." When creating a breadcrumb, you're simply creating a link. In the custom breadcrumbs interface "Titles" describes the text of the breadcrumb while "Paths" describes the Drupal path the breadcrumb links to. So each line of the title field corresponds to the equivalent line of the paths field. Thus, you must have the same number of titles and paths.

To give a very simple example of how to use this module, let's say I have a blog on my web site called "Deep Thoughts." To create this, I use the Views module to create a page at /blog that displays all the node types "blog post." Whenever a user views a blog post I want the breadcrumb to show Home > Deep Thoughts instead of simply Home. To do this I would simply type "Deep Thoughts" in the titles field and and "blog" in the paths field and save my breadcrumb. Then, the first item in the breadcrumb would say "Deep Thoughts" and link to the path "blog" (the location of views page that lists blog posts).

Working with Tokens

Using the Token module, the Custom Breadcrumbs module becomes much more flexible: breadcrumbs can be dynamic. So I could create a breadcrumb like Home > Deep Thoughts > [Month of Blog Post] [Year of Blog Post] Where "Deep Thoughts" links to my main blog page and "[Month of Blog Post] [Year of Blog Post]" links to a view that shows only blog posts from the month and year the blog post was created (e.g. June 2007). To do this, create a custom breadcrumb for the node type "blog":

Titles:
Deep Thoughts
[month] [yyyy]

Paths:
blog
blog/[mm]_[yyyy]

(where of course, blog/[mm]_[yyyy] is the path to the view of blog posts from that month and year).
So if I created a blog post today (June 13, 2007) my breadcrumb would show Home > Deep Thoughts > June 2007 and "June 2007" links to "blog/06_2007" which is a view of all blog posts from June 2007.

Also, note that Custom Breadcrumbs doesn't actually check to be sure that a particular path exists, so you'll have to check yourself to avoid 404 errors.

On PHP

SpriteGF - August 26, 2008 - 18:54

There's now a field titled "Breadcrumb visibility" that allows you to customize where your breadcrumbs are applied. In most cases, you can just insert "return TRUE;" in that field (without the <php> tags).

Excluding certain Node IDs

capellic - September 2, 2008 - 22:06

I setup a content type for pages in each one of the sections on my website. I don't want the section's landing page to have itself listed in the breadcrumbs, so I add this bit of code where the nid is the landing page:

<?php
if ($node->nid != 43) return TRUE;
?>

If your breadcrumbs don't show up...

SpriteGF - August 26, 2008 - 18:57

Your breadcrumbs might not appear at all because another module (e.g. Image module) may be prioritizing its own breadcrumb trail over your custom breadcrumb trail. If you find this is the case, you can give priority to the Custom Breadcrumbs module by increasing the "module weight". To do this, go to your MySQL database's system table, find the custom breadcrumbs module's entry, then change the weight of that module to something higher than the image module's weight, like 10.

(similar problem: http://drupal.org/node/278306 )

Appending current node title in plain text

tobiassjosten - August 26, 2008 - 20:00

For anyone wondering how to add the current node's title to the end of the breadcrumb, without an ugly theme hack, I would like to chip in with my suggestion. By using this module, you can for example set the custom breadcrumbs like this.

Titles:
Deep Thoughts
[month] [yyyy]
[title]

Paths:
blog
blog/[mm]_[yyyy]
<none>

The <none> token isn't listed but it works just as well, making the breadcrumb item a plain text string.

I would personally also apply proper CSS to differentiate the plain text from the links, so not to confuse the users and to make it more obvious that this list of links (breadcrumb) is a site map of sorts.

 
 

Drupal is a registered trademark of Dries Buytaert.