treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Using Last Class in NextGEN Gallery

  • I'm trying to add a "last" class on the end of every fourth thumbnail for styling.

    Here's the code:

    <div id="ngg-image-<?php echo $image->pid ?>" class="ngg-gallery-thumbnail-box" <?php echo $image->style ?> >
    <div class="ngg-gallery-thumbnail" >
    <a href="<?php echo $image->imageURL ?>" title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?> >
    <?php if ( !$image->hidden ) { ?>
    <img title="<?php echo $image->alttext ?>" alt="<?php echo $image->alttext ?>" src="<?php echo $image->thumbnailURL ?>" <?php echo $image->size ?> />
    <?php } ?>
    </a>
    </div>
    </div>
    Any help would be appreciated.

    Thanks in advance.
  • Put this in your gallery-caption.php

    <?php
         $count = 0;
        ?>
    
    
    <?php foreach ( $images as $image ) : ?>
    pid ?>" class="ngg-gallery-thumbnail-box" <?php echo $image->style ?> >
    " > imageURL ?>" title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?> > <?php if ( !$image->hidden ) { ?>  alttext ?>" alt="<?php echo $image->alttext ?>" src="<?php echo $image->thumbnailURL ?>" <?php echo $image->size ?> /> <?php } ?> <?php echo $image->caption ?>
    <?php if ( $image->hidden ) continue; ?>
    <?php if ( $gallery->columns > 0 && ++$i % $gallery->columns == 0 ) { ?>
    
    <?php } ?> <?php $count++; ?> <?php endforeach; ?>
  • or just use

    <?php
         $count = 0;
        ?>
    
      
      <?php foreach ( $images as $image ) : ?>

    And this is your class:

     id="<?php if ($count % 4 == 0) { echo "last"; } ?>" 

    and this

     
    <?php } ?> <?php $count++; ?> <?php endforeach; ?>
  • That seems complicated. Can't you use nth-of-type?