
Drupal 7 - Custom Breadcrumbs with PHP
Published: 10/23/2015
I have a content type called Features. This content type contains multiple subcategories of data, including News Releases, Awards, Informative Tips, and Patient Stories. This subcategory is a field on the content type, and is chosen when a Feature node is created. Because data pertains to different subcategories, I preferred to have the sub-category in the breadcrumb string. Below is how I accomplished this.
- Created the Content Type and all required fields.
- On the Edit Tab of the Content Type, checked the option 'Display defined custom breadcrumbs on node edit form'
- Navigated to admin/structure/custom_breadcrumbs
- On the Node tab, added a new breadcrumb, gave it a name of 'News Item' and associated it with the Node type of 'Features'.
- For Breadcrumb visibility, added the following PHP code:
if ($node->field_article_type['und'][0]['value'] == 'newsrelease') return TRUE;
- For Titles, added the display title of the breadcrumb, in this case 'News'
- For Path, entered the real path of the parent page. In this case, I wanted the parent breadcrumb to go to http://domain/newsroom (opens in new tab). So the path is simply 'newsroom'
- Repeated for the additional subcategories, using the machine name of the subcategory for each PHP statement
Below is a screen shot of my setup for News Releases:
