Views Breadcrumbs using Arguments

For most of my clients, I need to create Breadcrumbs. Seemingly easily, breadbrumbs is an area that is a bit more involved than most features in Drupal. There's a great module out there called custom_breadcrumbs. The module works great for the display of breadcrumbs on all node pages, but doesn't (yet) work with views.

After doing some research about a solution for view pages, here's my favorite pick: Views Arguments.

For a simple overview page (that uses views), add a "Global: Null" Argument. Within that argument, select "Provide default argument" and select "PHP Code". In here, you can use the drupal_set_breadcrumb function. That function accepts an array of link titles and paths. Here's an example:

$breadcrumb[] = l('Home', null);
$breadcrumb[] .= l('Is The Box Butler For Me?', 'use-cases');
drupal_set_breadcrumb($breadcrumb);

To make this work, it's important to select "Display All Values" for "Action to take if argument does not validate", otherwise the view gets messed up.

To be on the safe side, I've attached a screenshot of the arguments code for this (live) example: http://theboxbutler.com/use-cases.

Views Breadcrumbs using Arguments

Comments

Ok, having some trouble... I have set up everything according to your screen print but my NBA News view still doesn't want to co-operate with breadcrumbs.

$breadcrumb[] = l('Home', null);
$breadcrumb[] .= l('NBA Basketball News and Rumors', 'nba-news');
drupal_set_breadcrumb($breadcrumb);

NBA Basketball News and Rumors shows up perfectly and the link works as well, though, It doesn't quite perform as expect. This is what is showing up.

Home :: NBA Basketball News and Rumors :: Home

It has sort of a nifty look to it but I think I'd rather fix the error. ;-)

I'm thinking maybe I can just get rid of?

$breadcrumb[] = l('Home', null);

I'm new to Drupal though and you mentioned the view breaking so I'm not about to go experimental too much.

Hey there. I checked out the site and I'm not quite sure where the last "Home" is coming from. It's not coming from the view, as you're defining only links with the snipped that you used. If you remove the first one, there won't be a link back home. Check in your theme settings or theme php files to see if there's a hardcoded "Home" text floating around somewhere.

Ughh... Ok, as it turns out, with the Zen Theme or any of the sub-themes, there is an option...

Append the content title to the end of the breadcrumb
Useful when the breadcrumb is not placed just before the title.

Apparently I had that checked. It had nothing to do with either your Breadcrumbs solution or being hard coded in the theme (though it's always nice to have a quick look through code). Appreciate the help.

This comment about using the Append Page Title in the Zen theme configuration worked perfectly. Thanks!!

Hi Daniel,

Thanks allot... i have the same problem.... now completely solved...
Thank You,

Thank you for solving my same problem, which cost me a lot of money!!!
You article is really helpful !

Hey Daniel,

I was scratching my head over this for a while, googled it, and found this post. So thanks a bunch for posting this, it worked like a charm.

I believe we sat next to each other at Drupal Camp - in Frank Carey's presentation on Features - sorry I didn't introduce myself.

Well, hope to formally meet you some other time.

Harris.

Thanks for this Daniel, really helpful.
I was just wondering, is there something you can change in the php code to specify that the final crumb trail (page you're on) shouldn't be a link?

In custom breadcrumbs you can use , and it works perfectly.

Any help?

Thanks

Fantastic post!

David: I apologize for getting back to you this late about your question. Yes, you could easily change that. The following code should work:

$breadcrumb[] = l('Home', null);
$breadcrumb[] .= t('Is the Box Butler For Me?');
drupal_set_breadcrumb($breadcrumb);

Thank you so much! I've been trying to figure this out forever. Great tutorial.

This is a brilliantly simple technique, for a tricky task!
Is it posted on d.o?

Thankyou!

I can confirm that this also works in Drupal 7 - thanks so much