fieke
10/29/2013 - 12:53 PM

Top image

Top image

// TOP IMAGE
function _topimage() {
  global $language;

  // if we are on a node page
  if(arg(0) == 'node') {

    // get the current node
    $obj = menu_get_object();

    if(isset($obj->field_top_image['und']) && count($obj->field_top_image['und']) > 0){

      // count the number of images
      $countImages = sizeof($obj->field_top_image['und']);

      // get a random that we want to display
      $random = rand(0,($countImages-1));

      // loop through items
      for($i = 0; $i < $countImages; $i++) {

        // if item <> random => delete the item
        if($i != $random) {
          unset($obj->field_top_image['und'][$i]);
        }
      }
    }
    // get the node based on view mode top_image
    $view_mode = node_view($obj, 'topimage');

    // send to template
    return array(
      array(
        '#theme' => 'topimage',
        '#node' => $view_mode,
      ),
    );
    ;
    
  }
  return NULL;
}