Add icon to default taxonomy menu block
/**
* Implements taxonomy_menu_block__
*/
function theme_taxonomy_menu_block__1($variables) {
$tree = $variables['items'];
$config = $variables['config'];
$num_items = count($tree);
$i = 0;
$output = '<ul>';
foreach ($tree as $tid => $term) {
$i++;
// Add classes.
$attributes = array();
$attributes['class'][] = $i % 2 ? 'odd' : 'even';
if($i%3 == 0) {
$attributes['class'][] = 'third';
}
if($i%4== 0) {
$attributes['class'][] = 'fourth';
}
// Set alias option to true so we don't have to query for the alias every
// time, as this is cached anyway.
$output .= '<li' . drupal_attributes($attributes) . '>';
$output .= '<div class="icon">'.theme('image_style', array('style_name' => 'icon', 'path' => $term['icon'])).'</div>';
$output .= '<p>'.$term['name'].'</p>';
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
/**
* Implements hook_taxonomy_menu_block_tree_alter
*/
function custom_taxonomy_menu_block_tree_alter(&$tree, $config) {
switch($config) {
// add icon image to cache of TMB
case '2':
foreach($tree as $tid => $term) {
$termload = taxonomy_term_load($tid);
$tree[$tid]['icon'] = $termload->field_icon['und']['0']['uri'];
}
break;
}
}