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.

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.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
More information about formatting options
CAPTCHA
This question tests whether you are a human visitor and to prevent automated spam submissions.