Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

help in php coding for a wordpress template


  • Please log in to reply

#1
tha dj

tha dj

    Member

  • 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

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?

thank you guys, much appreciated.
  • 0

Advertisements


#2
tha dj

tha dj

    Member

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

<?php
$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