Title: Adding a random number to post_class
Last modified: August 20, 2016

---

# Adding a random number to post_class

 *  Resolved [photo_ed](https://wordpress.org/support/users/photo_ed/)
 * (@photo_ed)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-a-random-number-to-post_class/)
 * Hi everyone
 * I am working on a site want to have three random column widths. I found an example
   that hows me how to generate the random number for the class
 * `<a href="<?php the_permalink(); ?>" class="box col<?php echo rand(2,4); ?>">...
   </a>`
 * but in my theme I am using _post\_class()_ so I am not sure how to add the echo
   rand statement.
 *     ```
       <article id="post-<?php the_ID(); ?>" <?php post_class('box col'); ?>>
       ...
       </article>
       ```
   
 * I am still learning all this and have tried how I thought it should be concatenated
   but none of them worked. If someone could point me in a direction or tell me 
   a better way it would be greatly appreciated
 * Thx

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [wpismypuppet](https://wordpress.org/support/users/wordpressismypuppet/)
 * (@wordpressismypuppet)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-a-random-number-to-post_class/#post-2542574)
 * Try…
 *     ```
       <?php $num=rand(2,4); ?>
       <article id="post-<?php the_ID(); ?>" <?php post_class('box col'.$num); ?>>
       ...
       </article>
       ```
   
 * This isn’t tested, but I don’t see why it wouldn’t work.
 *  Thread Starter [photo_ed](https://wordpress.org/support/users/photo_ed/)
 * (@photo_ed)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/adding-a-random-number-to-post_class/#post-2542581)
 * That worked Thanks so much, I knew it was something simple I was overlooking.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Adding a random number to post_class’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [photo_ed](https://wordpress.org/support/users/photo_ed/)
 * Last activity: [14 years, 3 months ago](https://wordpress.org/support/topic/adding-a-random-number-to-post_class/#post-2542581)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
