Pagelist thumbnail

Permalink 1 user found helpful
I am creating a page-list of thubnails, much like this:http://mattgreydesign.com/projects/... however I would like every 3rd thumbnail to have a different class so the padding aligns them properly, how would I go about doing this using my existing code? ....

<div class="ccm-page-list-3">
<?php 
for ($i = 0; $i < count($cArray); $i++ ) {
   $cobj = $cArray[$i]; 
   $title = $cobj->getCollectionName(); ?>
    <div class="ccm-page-list-itm-3">
    <h3 class="listheader-3"><a href="<?php echo $nh->getLinkToCollection($cobj)?>"><?php echo $title?></a></h3>
<div class="ccm-page-list-description-3">
   <?php if($cobj->getAttribute('thumbnail')): ?>
<?php endif; ?>
   <?php 
   if(!$controller->truncateSummaries){
      echo $cobj->getCollectionDescription();
   }else{
      echo $textHelper->shortText($cobj->getCollectionDescription(),$controller->truncateChars);


Much appreciated

MattGreyDesign
 
Charlie replied on at Permalink Best Answer Reply
Hi Matt,

You can set up a variable to store an output count so that for every third iteration of the loop that outputs your thumbnails you can output a different class to the div.

Outside of the loop declare the variable, then within the loop increment and check its valu, either output the default class, or the alternative class and reset the counter.

The output count is $outputCount, for the third loop the class 'additionalClass' is used.

Amended code:

<?php
$outputCount = 0;
?>
<div class="ccm-page-list-3">
<?php 
for ($i = 0; $i < count($cArray); $i++ ) {
  $outputCount++;
   $cobj = $cArray[$i]; 
   $title = $cobj->getCollectionName(); ?>
 <?php
 if($outputCount == 3)
 {
    $outputCount = 0;
    echo '<div class="additionalClass">';
 } else {


Not tested, so please ensure you check and test code before deploying to a live environment, take a backup of the existing file.

Hope this helps,

Charlie.
MattGreyDesign replied on at Permalink Reply
MattGreyDesign
Ill give it a try, I thought it would use an array but I'm not that good at this type of thing...
MattGreyDesign replied on at Permalink Reply
MattGreyDesign
Worked like a charm, simple but effective, been trying to work it out for ages, thanks :~)
Charlie replied on at Permalink Reply
No worries, glad it helped :)