0

I'm using Drupal 7 and create a module for my content thumbnail images frontpage display. Working this:

 if(count($p_detail->field_slide) > 0){
            $output .= '<div class="right">';
            $output .= '<ul class="thumbs">';
            $i=6;
            foreach($p_detail->field_slide['und'] as $thumb):
                $img_path = $thumb['uri'];
                $img_url = image_style_url('tmb_240x117', $img_path);
                $img_file = '<img src="'.$img_url.'" alt="'.$p_detail->title.'" />';


                $output .= '<li>
                                <a href="'.$p_url.'">
                                    '.$img_file.'
                                    <div class="shadow"></div>    
                                    <div class="hoverimg"></div>
                                 </a>
                                <div class="img_no">0'.$i.'</div>
                            </li>';
                $i--;
            endforeach;
            $output .= '</ul>';
            $output .= '</div>';
        }

My thumbnails, field_slide and i want only first 6 thumbnails (if have 6 images... for exam, have 2 images, display 2 thumbnails)

How can i do this?

  • why are you not using a for() loop? – Drupac Jun 13 '12 at 16:58
1

If I understand you correctly then you just need to break out of the foreach loop after you got 6 thumbnails saved in the $output variable. With that addition the end of your loop would look like this:

if ($i == 1) break;
$i--;
endforeach;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.