Ever wanted to set adhock breadcrumbs for pages that were not really part of any logical menu structure? Also want to activate the primary menu for this ad hoc page?
Drupal 6 makes this easy....
In the rough example below, you can see how I go about setting a custom breadcrumb for taxonomy terms pages without hacking around the drupal core and without installing bunch of additional modules.
UPDATE:
since menu_set_active_item changes the $_GET['q'] value, you may have some unexpected issues if you are using the arg() function after using the menu_set_active_item() function anywhere in your hook_preprocess_page() function.
<?php
function mymodule_preprocess_page(&$variables){
$breadcrumb = mymodule_custom_breadcrumb($variables);
if($breadcrumb){
$variables['breadcrumb'] = $breadcrumb;
}
}
function mymodule_custom_breadcrumb($variables){
// taxonomy term page
if(arg(0) == 'taxonomy' and arg(1) == 'term' and is_numeric(arg(2))){
$term_obj = taxonomy_get_term(arg(2));
if($term_obj->vid == 1){
$parents = taxonomy_get_parents($term_obj->tid);
foreach ($parents as $parent_obj){
$breadcrumb[] = l($parent_obj->name, taxonomy_term_path($parent_obj));
}
}
$breadcrumb[] = l(t('foobar'), 'foobar');
}
if($breadcrumb){
$breadcrumb[] = l(t('Home'), NULL);
$breadcrumb = array_reverse($breadcrumb);
menu_set_active_item('foobar');
return theme('breadcrumb', $breadcrumb);
}
}
?>
















4 comments
25th Jun, 09
Nice one.
Last line should be theme('breadcrumb', $breadcrumb)
26th Jun, 09
Cheers Mosche, code updated :-)
23rd Jul, 09
If i want to to make any primary link active, where and how should i do it? im setting menu_set_active_item('mymenuitem'); in template _preprocess_page hook and seems to not work
27th Jul, 09
@ Marcin:
Can you please post your code so I can see how you are trying to implement this?
Post new comment