php - How to display images of a post in random order - Wordpress -


i have page in wordpress, in have added 3 images via "add media" button.

now, looking way display these images 1 @ time , in random order.

just guessing have call the_content of page , write php display images 1 @ time in random order? since don't know how write such function, huge!

enter image description here

you can find many plugins this. https://wordpress.org/plugins/tags/random-image/

or

if use custom post type might full you.

use array_unique() before foreach:

<?php while ( have_posts() ) : the_post();      $images = get_field('gallery');      // thumbnail     if( $images ):  ?>     <ul id="container" class="tiles-wrap animated">         <?php              $images = array_rand($images);              $images = array_unique($images);              foreach( $images $image ):                   // $rand_class = array('small', 'medium', 'large');                 $size = 'medium';                 $thumb = $image['sizes'][ $size ];                 $width = $image['sizes'][ $size . '-width' ];                 $height = $image['sizes'][ $size . '-height' ]; ?>                 <li><img src="<?php echo $image['sizes']['medium']; ?>" alt="<?php echo $image['alt']; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>" /></li>                     <?php endforeach;        endif; ?>     </ul> <?php endwhile; ?> 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -