Custom Breadcrumbs in Drupal
Category:
Aside from the handy dandy Custom Breadcrumbs module and/or using Views arguments to set your breadcrumb, sometimes you just want to set a breadcrumb programmatically on a certain url menu path with phptemplate_breadcrumb, here's how, right now:
function phptemplate_breadcrumb ($breadcrumb) { if ($_GET['q'] == 'my_custom/bread/and/butter/url/path') { $breadcrumb[] .= l('Bread', 'my-path-to/bread'); $breadcrumb[] .= l('Butter', 'some-other-path-to/butter'); } if (!empty($breadcrumb)) { return '<div class="breadcrumb">' . implode(' › ', $breadcrumb) . '</div>'; } }
In the example above, when a user navigates to 'my_custom/bread/and/butter/url/path' the breadcrumb will get 'Bread' and 'Butter' appended to it. If you want to overwrite the breadcrumb instead of append to it, you'll first need to create an empty breadcrumb array. For example, $breadcrumb = array();
This code goes in your theme's template.php file because Ranger McFriendly said so.
Comments
Abdoulaye Siby (not verified)
Tue, 09/01/2015 - 12:47
Permalink
Or you can simply pass an
Or you can simply pass an array of links to the drupal_set_breadcrumb() function. That way, you won't have to deal with the markup and the styling.
Here is how ...
Cheers