Try the Demo

Magento Forum

   
PHP Call Alternating CSS Class
 
toman01
Sr. Member
 
Total Posts:  92
Joined:  2008-03-07
 

I would like to give the gallery thumbnails on the product pages alternating CSS classes.

In other words, I would like to give the first thumbnail the “.mycssclass1”, the second thumbnail “.mycssclass2”, and then repeat in that order, always alternating between the two classes.

The reason I need such function is to float half of the thumbnails to the left and half to the right.

I really appreciate any help in this.

P.S. Sorry if the title of this post does not make sense, but as I am a layman when it comes to PHP, I did not quite know how to express this problem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
toman01
Sr. Member
 
Total Posts:  92
Joined:  2008-03-07
 

I found the solution. Simply replace the content in template/catalog/product/view/media.phtml with:

<?php $_product $this->getProduct() ?>
<?php 
if (count($this->getGalleryImages()) > 0): ?>
<div class="more-views">
<
h4><?php echo $this->__('Sample Images'?></h4>


<?php $counter 0; foreach ($this->getGalleryImages() as $_image{
  
   
if ($counter == 0{
 $class 
=1;
}
else {
 $class
=2;
}
$counter
++; ?>
<div <?php echo 'class="gal-pic' $class '"'?>>
<
a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image); ?>', 'gallery', 'scrollbars=yes,width=300,height=300,resizable=yes');return false;" >
<
img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->directResize(140, 300, 1); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()); ?>" title="<?php echo $this->htmlEscape($_image->getLabel()); ?>" /></a></div>

<?php } ?></div><?php endif; ?>

Of course you can further customize it to your needs.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top