Search code examples
arrayswordpresssliderlimitthumbnails

Wordpress slider thumb, how to limit to first 6 with array?


I'm trying to limit the thumbs shown by the following code to the first 6 items in the slider, only I can't get it to work. Does anyone know how to do what I'm looking for please?

<ul class="pictures-2">
<?php
foreach( $properties_images as $prop_image_id=>$prop_image_meta ){
$slider_thumb = wp_get_attachment_image_src($prop_image_id,'property-thumb-image');
echo '<li>';
echo '<img src="'.$slider_thumb[0].'" alt="'.$prop_image_meta['title'].'" />';
echo '</li>';
}
?>
</ul>

Solution

  • <ul class="pictures-2">
        <?php
        $i=0;
        foreach( $properties_images as $prop_image_id=>$prop_image_meta ){
            $i++;
            if ($i <= 6) {
                $slider_thumb = wp_get_attachment_image_src($prop_image_id,'property-thumb-image');
                echo '<li>';
                echo '<img src="'.$slider_thumb[0].'" alt="'.$prop_image_meta['title'].'" />';
                echo '</li>';
            } else {
                //Do Nothing
            }
        }
    ?>
    </ul>