Created
September 24, 2013 10:45
-
-
Save vdchristelle/6683071 to your computer and use it in GitHub Desktop.
Adds an icon to a taxonomy menu block item link - hook taxonomy menu block - rewrite output TMB - TMB term teasers
This file contains hidden or 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 hidden or 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(); | |
| 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment