Created
September 18, 2013 06:58
-
-
Save fieke/6605479 to your computer and use it in GitHub Desktop.
Add icon to default taxonomy menu block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment