How to add breadcrumb?

Umar Adil picture Umar Adil · Apr 10, 2012 · Viewed 7.9k times · Source

How can I add breadcrumb to a page in my attendance module.

I have used the following hook, but it changed the breadcrumb for all pages in other modules also.

function attendance_init() {
// set the breadcrumb
$breadcrumb = array();
$breadcrumb[] = l('Home', '<front>');
$breadcrumb[] = l('People', 'group/node/'. arg(2) .'/people');
$breadcrumb[] = l('Attendance', 'group/node/'. arg(2) .'/people/attendance');
drupal_set_breadcrumb($breadcrumb);         
}

Answer

Muhammad Reda picture Muhammad Reda · Apr 11, 2012

If you are trying to change the breadcrumb for a specific content type nodes, try to use hook_node_view_alter()

Here's an example:

function attendance_node_view_alter(&$build)
{
    $node = $build['#node'];
    if($build['#view_mode'] == "full" && $node->type == "attendance")
    {
        $breadcrumb = array();
        $breadcrumb[] = l('Home', '<front>');
        $breadcrumb[] = l('People', 'group/node/'. arg(2) .'/people');
        $breadcrumb[] = l('Attendance', 'group/node/'. arg(2) .'/people/attendance');
        drupal_set_breadcrumb($breadcrumb);
    }
}

Hope this works... Muhammad