Title: random php template
Last modified: August 19, 2016

---

# random php template

 *  Resolved [M1chel](https://wordpress.org/support/users/m1chel/)
 * (@m1chel)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/random-php-template/)
 * Hi everybody, I’m michel.
 * I’m trying to solve a simple problem, just a matter of syntax probably but I 
   don’t know php and I’m learning now to use wordpress’ tags..
 * so, I had to display randomly 4 different columns in a page, but in the column
   there’s a div containing an image and a title with a link to a post, so things
   got a little complicated and I figured including a php template was a good solution.
   
   Let’s say I created 3 php pages named cat-4-feat-1.php , cat-4-feat-2.php , cat-
   4-feat-3.php in which the code is:
 *     ```
       <div class="box_pict">
   
       <?php
   
       query_posts('p=20');
       ?>
       <?php while (have_posts()) : the_post(); ?>
   
          <a id="pict_featured_3" href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
             <img class="c" src="http://localhost/wordpress/wp-content/uploads/2009/07/featured_1.jpg" />
             <p id="post_37">
             inspiration 4
             </p>
          </a>
   
       <?php endwhile; ?>
   
       </div>
       ```
   
 * (obviously the post id and the image number change every time)
 * and I included the template in my page with:
 *     ```
       <?php include( TEMPLATEPATH . '/cat-4-feat-3.php' ); ?>
       ```
   
 * but I need to modify that path with a function to make the number random.
    I’ve
   seen using something like this: `<?php echo(rand(1,5)); ?>` but I don’t know 
   how to use it in this situation coz I’m not familiar with php language.
 * can you help?

Viewing 1 replies (of 1 total)

 *  Thread Starter [M1chel](https://wordpress.org/support/users/m1chel/)
 * (@m1chel)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/random-php-template/#post-1142508)
 * ok, thanks, I find a solution this way:
    <?php $numero = rand(1,3); include( 
   TEMPLATEPATH . ‘/cat-4-feat-‘ . $numero . ‘.php’); ?>
 * 🙂

Viewing 1 replies (of 1 total)

The topic ‘random php template’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [M1chel](https://wordpress.org/support/users/m1chel/)
 * Last activity: [16 years, 11 months ago](https://wordpress.org/support/topic/random-php-template/#post-1142508)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
