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('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.
- Login to post comments
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.
- Login to post comments
This comment about using the Append Page Title in the Zen theme configuration worked perfectly. Thanks!!
- Login to post comments
Hi Daniel,
Thanks allot... i have the same problem.... now completely solved...
Thank You,
- Login to post comments
Thank you for solving my same problem, which cost me a lot of money!!!
You article is really helpful !
- Login to post comments
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.
- Login to post comments
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
- Login to post comments
Thank you so much! I've been trying to figure this out forever. Great tutorial.
- Login to post comments
This is a brilliantly simple technique, for a tricky task!
Is it posted on d.o?
Thankyou!
- Login to post comments
I can confirm that this also works in Drupal 7 - thanks so much
- Login to post comments























