Title: php function needed &#8211; &quot;De-randomize&quot;?
Last modified: August 20, 2016

---

# php function needed – "De-randomize"?

 *  [simto](https://wordpress.org/support/users/simto/)
 * (@simto)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/php-function-needed-de-randomize/)
 * Hello
 * I really like Chris Coyiers post about a “[Randomized grid of Posts](http://digwp.com/2010/08/randomized-grid-of-posts/)“
 * I don’t know php that well, so I would like to hear if you could help with the
   following: In Chris’ post he writes the following for handling the content:
 *     ```
       <a href="<?php the_permalink(); ?>" class="box col<?php echo rand(2,4); ?>">
             <span class="title"><?php the_title(); ?></span>
             <img src="<?php echo get_post_meta($post->ID, 'PostThumb', true); ?>" alt="" />
             <span class="ex"><?php the_excerpt(); ?></span>
           </a>
       ```
   
 * As I understand it this part: `<?php echo rand(2,4); ?>`, is what “randomizes”
   the grid by choosing a random number between 2,3 and 4 for each box.
 * I would very much like to do the opposite, but I don’t know the command in php.
   I would like to get a ordered sequence of boxes, eg. 1,2,3,4,5,1,2,3,4,5,1,2,3,4,5
   etc. Is it possible to change the “echo rand” command so it does the opposite–
   an ordered array/sequence of numbers?
 * Hope you can help…
 * Cheers

Viewing 1 replies (of 1 total)

 *  [BoUk](https://wordpress.org/support/users/bouk/)
 * (@bouk)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/php-function-needed-de-randomize/#post-3597862)
 * Hi,
 * You can try something like this:
 *     ```
       <?php if (have_posts()) : ?>
       <?php $i = 1; ?>
       <?php while (have_posts()) : the_post(); ?>
   
       			<a href="<?php the_permalink(); ?>" class="box col<?php echo $i; ?>">
       				<span class="title"><?php the_title(); ?></span>
       				<img src="<?php echo get_post_meta($post->ID, 'PostThumb', true); ?>" alt="" />
       				<span class="ex"><?php the_excerpt(); ?></span>
       			</a>
             <?php 
   
               $i++;
   
               if ( $i%5 == 0 ) $i = 1;
   
             ?>
       <?php endwhile; ?>
       <?php endif; ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘php function needed – "De-randomize"?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [BoUk](https://wordpress.org/support/users/bouk/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/php-function-needed-de-randomize/#post-3597862)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
