ADVANCED CUSTOM FIELDでランダムにギャラリーを呼び出す関数

$max = の部分を好きな数に変えるだけ

 

<?php $images = get_field('photo_gallery','17'); if( $images ): shuffle($images); // randomizes the image array $max = 10; // set the max here; $count = 0; // current count ?>


<ul>
        <?php foreach( $images as $image ): $count++; // increment count // if count is greater than limt, stop showing images if ($count > $max) {
                    break;
                }
         ?>


<li>
                <a href="<?php echo $image['url']; ?>" rel="lightbox">
                     <img src="<?php echo $image['sizes']['photo-gallery']; ?>" alt="<?php echo $image['alt']; ?>" />
                </a>
            </li>


        <?php endforeach; ?>


<div id="clearfloat"></div>


    </ul>


<?php endif; ?>

関連記事