vdchristelle
9/24/2013 - 10:45 AM

Adds an icon to a taxonomy menu block item link - hook taxonomy menu block - rewrite output TMB - TMB term teasers

Adds an icon to a taxonomy menu block item link - hook taxonomy menu block - rewrite output TMB - TMB term teasers

/**
 * 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;
    
  }
}
/**
 * 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(); 
 
    if($i == 1){
      $attributes['class'][] = 'first';
    }

    $attributes['class'][] = $i % 2 ? 'odd' : 'even'; 
 
    if($i%3 == 0) {
      $attributes['class'][] = 'third';
    }
 
    if($i%4== 0) {
      $attributes['class'][] = 'fourth';
    }

    if($i == $num_items){
      $attributes['class'][] = 'last';
    }
 
    // 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;
}