Last active
August 29, 2015 14:06
-
-
Save otarza/95ec6d276a9a08ef6504 to your computer and use it in GitHub Desktop.
3x4 grid on drupal
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
| .grid-wrapper ul li { | |
| list-style: none; | |
| float: left; | |
| display: block; | |
| width: 32%; | |
| margin-right: 1%; | |
| } | |
| .grid-wrapper ul li img { | |
| max-width: 100%; | |
| } | |
| .row-of-three { | |
| width: 100%; | |
| display: block; | |
| float: left; | |
| } | |
| .row-of-three li { | |
| list-style: none; | |
| } |
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 | |
| /** | |
| * Implements hook_menu(). | |
| */ | |
| function grid_menu() { | |
| $items['testme'] = array( | |
| 'page callback' => 'grid_print_items', | |
| 'access arguments' => array('access content'), | |
| 'type' => MENU_CALLBACK, | |
| ); | |
| return $items; | |
| } | |
| /** | |
| * Implements menu callback. | |
| */ | |
| function grid_get_items() { | |
| drupal_add_css(drupal_get_path('module', 'grid') . '/css/grid.css', array('weight' => 10, 'group' => CSS_THEME,)); | |
| $query = new EntityFieldQuery(); | |
| $query->entityCondition('entity_type', 'node') | |
| ->entityCondition('bundle', 'article') | |
| ->propertyCondition('status', 1) | |
| ->fieldCondition('field_number', 'value', 0, '>') | |
| ->fieldCondition('field_number', 'value', 13, '<') | |
| ->fieldOrderBy('field_number', 'value', 'ASC'); | |
| $result = $query->execute(); | |
| $grid_items = array(); | |
| if (isset($result['node'])) { | |
| $grid_items_nids = array_keys($result['node']); | |
| $grid_items = entity_load('node', $grid_items_nids); | |
| } | |
| return $grid_items; | |
| } | |
| function grid_print_items() { | |
| $grid_items = grid_get_items(); | |
| return theme('grid_items', array("grid_items" => $grid_items)); | |
| } | |
| /** | |
| * Implements hook_node_presave(). | |
| */ | |
| function grid_node_presave($node) { | |
| $grid_items = grid_get_items(); | |
| $current_number = $node->field_number['und'][0]['value']; | |
| if (is_numeric($current_number) && $current_number > 0 && $current_number < 13) { | |
| foreach ($grid_items as $grid_item) { | |
| $grid_item_number = $grid_item->field_number['und'][0]['value']; | |
| if ($node->nid != $grid_item->nid && $grid_item_number == $current_number) { | |
| $grid_item->field_number['und'][0]['value']++; | |
| node_save($grid_item); | |
| } | |
| } | |
| } | |
| } | |
| /** | |
| * Implements hook_theme(). | |
| */ | |
| function grid_theme($existing, $type, $theme, $path) { | |
| return array( | |
| 'grid_items' => array( | |
| 'template' => 'tpl/grid_items', | |
| 'arguments' => array('grid_items' => null), | |
| ), | |
| ); | |
| } |
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
| <div class="grid-wrapper"> | |
| <ul> | |
| <?php $i = 0; ?> | |
| <?php foreach ($grid_items as $grid_item): ?> | |
| <?php $i++; ?> | |
| <?php ($i % 3 == 1) ? print '<div class="row-of-three">' : ''; ?> | |
| <li class="grid-item"> | |
| <h1> <?php print $grid_item->title; ?> </h1> | |
| <a href="<?php print drupal_get_path_alias("node/" . $grid_item->nid); ?>"> | |
| <img src="<?php print file_create_url($grid_item->field_image['und'][0]['uri']); ?>"> | |
| </a> | |
| </li> | |
| <?php ($i % 3 == 0) ? print '</div>' : ''; ?> | |
| <?php endforeach; ?> | |
| </ul> | |
| </div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment