Creating a grid of images for an album in Drupal 6

Following on from the tutorial of creating an album based gallery in Drupal 6. This tutorial will teach you how to create a basic grid of the images in the node.

Update: I have written an updated tutorial with code to allow you to have pagination on your grid of images.

In your content type, go to Display fields and set the Full node to <Hidden>. This will take the images out of the $content variable.

Then in your theme, copy the existing node.tpl.php and create a new identical file called node-album.tpl.php (the album part with be the content type name that you used from the tutorial.)

Below the content section, add the following PHP code:

<?php
$images 
$node->field_images;
if (
count($images) > 0):
  
$rows = array();
  
$images_per_row 3;
  
$i 0;
  
$row 0;
  foreach (
$images as $image) {
    
$rows[$row][$i] = '<a class="gallery-thumbs" title="'htmlspecialchars($image['data']['description']) .'" rel="lightbox[photo_gallery-'$node->nid .']" href="'imagecache_create_url('lightbox'$image['filepath']) .'">'theme('imagecache''thumbnail'$image['filepath'], $image['data']['title'], $image['data']['title']) .(trim($image['data']['description']) != '' '<br /><small>'$image['data']['description'] .'</small></a>' '');
    
$i++;
    if (
$i == $images_per_row) {
      
$row++;
      
$i 0;
    }
  }
?>
<table class="views-view-grid">
  <tbody>
    <?php foreach ($rows as $row_number => $columns): ?>
      <?php
        $row_class 
'row-' . ($row_number 1);
        if (
$row_number == 0) {
          
$row_class .= ' row-first';
        }
        elseif (
count($rows) == ($row_number 1)) {
          
$row_class .= ' row-last';
        }
      
?>
      <tr class="<?php print $row_class?>">
        <?php foreach ($columns as $column_number => $item): ?>
          <td class="<?php print 'col-'. ($column_number 1); ?>">
            <?php print $item?>
          </td>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>
<?php else: ?>
  <p>No images in album</p>
<?php endif; ?>

The table code is a direct copy from views-view-grid.tpl.php so the code should look identical to the Album view.

Replace the following with your own settings:

<?php imagecache_create_url('lightbox'$image['filepath']); ?>

Change lightbox for the name of the imagecache preset that should open up within the lightbox.

<?php theme('imagecache''thumbnail'$image['filepath'], $image['title'], $image['title']); ?>

Change thumbnail to the name of the imagecache preset that should be displayed.

To add more columns to your grid, change the $images_per_row variable.

Update: I have written an updated tutorial with code to allow you to have pagination on your grid of images.