Created
October 25, 2013 09:42
-
-
Save vdchristelle/7152191 to your computer and use it in GitHub Desktop.
custom menu block of siblings with icon
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
| <?php | |
| $max = count(element_children($nodes)); | |
| // Set up striping values. | |
| $count = 0; | |
| ?> | |
| <div class="overview realisaties homepage"> | |
| <ul> | |
| <?php foreach ($nodes as $node) { | |
| $count++; | |
| $attributes = array(); | |
| $attributes['class'][] = 'colorcode-'.$node->nid; | |
| $attributes['class'][] = '' . ($count % 2 ? 'odd' : 'even'); | |
| if ($count % 3 == 0) { | |
| $attributes['class'][] = 'third'; | |
| } | |
| if ($count % 4 == 0) { | |
| $attributes['class'][] = 'fourth'; | |
| } | |
| ?> | |
| <?php | |
| $path = drupal_get_path_alias('node/'.$node->nid); | |
| if( isset($node->field_icon['und'][0]['uri']) && !empty($node->field_icon['und'][0]['uri'])){ | |
| $image_style = image_style_url('icon', $node->field_icon['und'][0]['uri']); | |
| dpm($node->field_icon['und'][0]['uri']); | |
| } else { | |
| $uri = 'public://icons/'.'default-icon-512.png'; | |
| $image_style = image_style_url('icon', $uri); | |
| } | |
| ?> | |
| <li <?php print drupal_attributes($attributes); ?>> | |
| <?php print '<img src="'.$image_style.'"/>'; ?> | |
| <?php print '<a href="'.$path.'">'.$node->title.'</a>'; ?> | |
| <?php print '<h2>'.$node->title.'</h2>'; ?> | |
| </li> | |
| <?php } ?> | |
| </ul> | |
| </div> |
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
| <?php | |
| /** | |
| * Implementation of hook_block_info(). | |
| */ | |
| function the_aim_custom_block_info() { | |
| // siblings block | |
| $blocks['siblings'] = array( | |
| 'info' => t('Sibling pages'), | |
| ); | |
| // subpages block | |
| $blocks['subpages'] = array( | |
| 'info' => t('Subpages'), | |
| ); | |
| return $blocks; | |
| } | |
| /** | |
| * Implementation of hook_block_view(). | |
| */ | |
| function the_aim_custom_block_view($delta='') { | |
| $block = array(); | |
| global $language; | |
| switch ($delta) { | |
| case 'siblings': | |
| $block['subject'] = t('Sibling pages'); | |
| $block['content'] = _siblings(); | |
| break; | |
| case 'subpages': | |
| $block['subject'] = t('Subpages'); | |
| $block['content'] = _subpages(); | |
| break; | |
| } | |
| return $block; | |
| } | |
| /* | |
| * Menu block siblings | |
| * content function | |
| */ | |
| function _siblings() { | |
| global $language; | |
| $node = menu_get_object(); | |
| $parent = db_select('menu_links', 'm') | |
| ->fields('m', array('plid')) | |
| ->condition('link_path', 'node/' . $node->nid) | |
| ->execute()->fetchField(); | |
| if (isset($parent) && $parent != 0) { | |
| $children = db_select('menu_links', 'm') | |
| ->fields('m', array('link_path')) | |
| ->condition('plid', $parent) | |
| ->execute()->fetchCol(); | |
| } | |
| if (isset($children) && count($children > 0)) { | |
| $regex = '/([^\/]*)\/([\d]+)/'; | |
| $matches = array(); | |
| foreach($children as $link_path){ | |
| preg_match($regex, $link_path, $matches); | |
| if(isset($matches[2])){ | |
| $node_results[] = $matches[2]; | |
| } | |
| } | |
| } | |
| if ($node_results) { | |
| $nids = array(); | |
| foreach ($node_results as $node_result) { | |
| $nids[] = $node_result; | |
| } | |
| if (!empty($nids)) { | |
| $nodes = node_load_multiple($nids); | |
| return array( | |
| array( | |
| '#theme' => 'subpages', | |
| '#nodes' => $nodes, | |
| ), | |
| ); | |
| ; | |
| } | |
| } | |
| return NULL; | |
| } | |
| /* | |
| * Menu block children | |
| * content function | |
| */ | |
| function _subpages() { | |
| global $language; | |
| $node = menu_get_object(); | |
| $parent = db_select('menu_links', 'm') | |
| ->fields('m', array('mlid')) | |
| ->condition('link_path', 'node/' . $node->nid) | |
| ->execute()->fetchField(); | |
| if (isset($parent) && $parent != 0) { | |
| $children = db_select('menu_links', 'm') | |
| ->fields('m', array('link_path')) | |
| ->condition('plid', $parent) | |
| ->execute()->fetchCol(); | |
| } | |
| if (isset($children) && count($children > 0)) { | |
| $regex = '/([^\/]*)\/([\d]+)/'; | |
| $matches = array(); | |
| foreach($children as $link_path){ | |
| preg_match($regex, $link_path, $matches); | |
| if(isset($matches[2])){ | |
| $node_results[] = $matches[2]; | |
| } | |
| } | |
| } | |
| if ($node_results) { | |
| $nids = array(); | |
| foreach ($node_results as $node_result) { | |
| $nids[] = $node_result; | |
| } | |
| if (!empty($nids)) { | |
| $nodes = node_load_multiple($nids); | |
| return array( | |
| array( | |
| '#theme' => 'subpages', | |
| '#nodes' => $nodes, | |
| ), | |
| ); | |
| ; | |
| } | |
| } | |
| return NULL; | |
| } | |
| function the_aim_custom_theme() { | |
| return array( | |
| 'siblings' => array( | |
| 'variables' => array( | |
| 'nodes' => NULL | |
| ), | |
| 'template' => 'block-subpages' | |
| ), | |
| 'subpages' => array( | |
| 'variables' => array( | |
| 'nodes' => NULL | |
| ), | |
| 'template' => 'block-subpages' | |
| ) | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment