Temi

In questa sezione vengono raccolte le più comuni domande sui temi di drupal, nella sezione si cerca di comprire tutti gli argomenti: reperimento, installazione e modifica.

Temizzare la image gallery (modulo image) per drupal 6

Per temizzare la image gallery di drupal 6 è necessario creare il file "image_gallery.tpl.php" e copiarlo sotto il proprio tema.
All'interno del file scriveremo il seguente codice:

<?php
$size
= image_get_sizes('thumbnail');
 
$width = $size['width'];
 
$height = $size['height'];
 
drupal_add_css(drupal_get_path('module', 'image_gallery') .'/image_gallery.css');
 
$content = '';
  if (
count($galleries)) {
   
$content.= '<ul class="galleries">';
    foreach (
$galleries as $gallery) {
     
$content .= '<li class="clear-block">';
      if (
$gallery->count)
       
$content .= l(image_display($gallery->latest, IMAGE_THUMBNAIL), 'image/tid/'. $gallery->tid, array('html' => TRUE));
       
// $content.= l(image_display($gallery->latest, 'thumbnail'), 'image/tid/'.$gallery->tid, array(), NULL, NULL, FALSE, TRUE);
     
$content.= "<h3>".l($gallery->name, 'image/tid/'.$gallery->tid) . "</h3>\n";
     
$content.= '<div class="description">'. check_markup($gallery->description) ."</div>\n";
     
$content.= '<p class="count">' . format_plural($gallery->count, 'There is 1 image in this gallery', 'There are @count images in this gallery') . "</p>\n";
      if (
$gallery->latest->changed) {
       
$content.= '<p class="last">'. t('Last updated: @date', array('@date' => format_date($gallery->latest->changed))) . "</p>\n";
      }
     
$content.= "</li>\n";
    }
   
$content.= "</ul>\n";
  }
  if (
count($images)) {
   
$height += 5;
   
$content = 'this is the list of galleries<br><br>';
   
$content.= '<ul class="images">';
    foreach (
$images as $image) {
     
$content .= '<li';
      if (
$image->sticky) {
       
$content .= ' class="sticky"';
      }
     
$content .= " style='height : ".$height."px; width : ".$width."px;'>\n";
     
$content .= l(image_display($image, IMAGE_THUMBNAIL), 'node/'. $image->nid, array('html' => TRUE));
     
$content .= '<h3>'. l($image->title, 'node/'. $image->nid) .'</h3>';
      if (
variable_get('image_gallery_node_info', 0)) {
       
$content .= '<div class="author">'. t('Posted by: !name', array('!name' => theme('username', $image))) ."</div>\n";
        if (
$image->created > 0) {
         
$content .= '<div class="date">'. format_date($image->created) ."</div>\n";
        }
      }
     
$content .= "</li>\n";
    }
   
$content.= "</ul>\n";
  }
  if (
$pager = theme('pager', NULL, variable_get('image_images_per_page', 6), 0)) {
   
$content.= $pager;
  }
  If (
count($images) + count($galleries) == 0) {
      
$content.= '<p class="count">' . format_plural($gallery->count, 'There is 1 image in this gallery', 'There are @count images in this gallery') . "</p>\n";
  }
  print
$content;
?>

In questo modo, al momento di visualizzare la galleria, verrà richiamato il codice sopra, che provvede a temizzare il tutto.
Dobbiamo fare due considerazioni:

1) non essendo obbligatorio, fornire la lunghezza e l'altezza per le anteprime (thumbnail), potremmo avere un valore falsato nella variabile $width o $height. Tenetene conto, facendo voi un calcolo su una anteprima oppure mettendo un semplice if tipo:

<?php
if ($height=='') $height = 150;
?>

subito sotto
<?php
$size
= image_get_sizes('thumbnail');
 
$width = $size['width'];
 
$height = $size['height'];
?>

2) L'istruzione drupal_add_css(drupal_get_path('module', 'image_gallery') .'/image_gallery.css'); carica un css esterno, che andrà posto sotto il proprio tema. Nel mio caso son partito dal vecchio esempio della 4.7, che trovate sotto:

ul.galleries {
  list-style-type : none;
  margin : 0;
  padding : 0;
}
ul.galleries li {
  position : relative;
  background : #eeeeee;
  border : 1px #cccccc solid;
  margin : 1em 0;
  padding : 1em;
}
ul.galleries li img {
  float : left;
  position : relative;
  padding-right : 4px;
  margin-right : 4px;
}
ul.galleries li .count,
ul.galleries li .last {
  clear : left;
  margin : 0;
  padding : 0;
  font-style : italic;
}
ul.galleries h3 {
  margin : 0;
  padding : 0;
}
ul.images {
  list-style-type : none;
  margin : 0;
  padding : 0;
}
ul.images h3 {
  font-size:1em;
  padding : 0;
}
ul.images li {
  float : left;
  margin : 1em;
  background: transparent;
}