Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

help in php coding for a wordpress template

  • Please log in to reply

tha dj

tha dj


  • Member
  • PipPip
  • 38 posts
Hi everybody, thanks in advance.

the short question:
I have this tag:
<?php include( TEMPLATEPATH . '/cat-4-feat-3.php' ); ?>
but I want to make the last number of the page's path random.
do you know the code I can use?

the question explained:

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 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

<?php endwhile; ?>


(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?

thank you guys, much appreciated.
  • 0


tha dj

tha dj


  • Topic Starter
  • Member
  • PipPip
  • 38 posts
ok, thanks everyone, I already found a solution thanks to a friend suggestion:

$numero = rand(1,3);
include( TEMPLATEPATH . '/cat-4-feat-' . $numero . '.php');

hope it can be useful for someone else as well
  • 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP