Adding Custom Breadcrumbs to Views Pages
on
Adding Custom Breadcrumbs to Views Pages
Recently I needed to add custom breadcrumbs to views 2 generated pages. Now we were using excellent custom_breadcrumbs 1.x to add custom breadcrumbs on site. At that time I discovered that 1.x version of custom_breadcrumbs do not support views generated pages and 2.x version of module (which supports views) is not production stable. So I came up with this solution to create custom breadcrumbs for views pages:
Lets say we have a page view with structure
---Team (menu item)
|
|---Featured 1 (tab-default)
|
|---Featured 2 (tab)
|
|---Featured 3 (tab)
Now instead of having a breadcrumb like "Home ›" OR "Home › Team ›" we need something like "Home › Our Team › Featured 1" for default tab. To accomplish this we need to add following php code in header section of view page with php filter enabled.
<?php
global $base_url;
$breadcrumb[] = l('Home', null);
$breadcrumb[] .= l('Our Team', 'team');
$breadcrumb[] .= l(drupal_get_title(), $base_url.$_SERVER['REQUEST_URI']);
drupal_set_breadcrumb($breadcrumb);
?>
Now this custom php will set new breadcrumb of page as:

Thanks for the ideas. It works fine. I want to ask about security... Is it really risky to apply this PHP code ?! At my site it's only user =1 who can use PHP format. Do I need to do something else to guard my site?!
PHP in the UI is bad for so many reasons (security, performance, maintainability, etc.). You'd be better off implementing hook_views_post_view() or hook_views_pre_view(): http://drupal.org/node/99567
Why use .= instead of =? Dot isn't necessary.
Why not use $_GET['q'] instead of $base_url.$_SERVER['REQUEST_URI']?








I want to ask what modification I need to do to this code in order to show "drupal_get_title()" without link to page. I don't need to link to a page that I am currently viewing. Is it possible to only get the page title without linking to it in the breadcrumb trail (line)?!
<code><?php
global $base_url;
$breadcrumb[] = l('Home', null);
$breadcrumb[] .= l('Our Team', 'team');
$breadcrumb[] .= l(drupal_get_title(), $base_url.$_SERVER['REQUEST_URI']);
drupal_set_breadcrumb($breadcrumb);
?></code>