Jump to content

Ramdom image


tommytomato

Recommended Posts

hi all

 

I've got this bit of code from a site I'm building in Wordpress

is there any way I can change it to show ramdom images  :confused:

 

I'm quiet new to PHP myself but have use CMS and edited a few pages to suit my needs

 

can any one show me how please

 

<div class="125ads">

 

<a href="#"><img src="<?php bloginfo('stylesheet_directory');?>/images/125x125.gif" alt="image file #1" width="125" height="125" /></a>

 

<a href="#"><img src="<?php bloginfo('stylesheet_directory');?>/images/125x125.gif" alt="image file #2" width="125" height="125" /></a>

 

<a href="#"><img src="<?php bloginfo('stylesheet_directory');?>/images/125x125.gif" alt="image file #3" width="125" height="125" /></a>

 

</div>

 

thanks TT

Link to comment
Share on other sites

Do something like this:

 

<?php
$images = array('image1.jpg', 'image2.png', 'image3.jpg');
?>

<a href="#"><img src="<?php bloginfo('stylesheet_directory');?>/images/<?php $images[array_rand($images, 1)]; ?>" alt="image file #2" width="125" height="125" /></a>

 

$images can contain any file-name and file-type as long as it actually exists.

With that code you can do this

Link to comment
Share on other sites

No luck with either source  :confused:

 

not to sure on what to do, but I copy and paste it in a few different ways,

 

<?php
$dir="./";   ( yes I changed the path )
$nimg="10";
$itype="jpg";
$bor="1";

$rnumb=rand(1,$nimg);

echo ""<img src=".$dir."".$rnumb."".$itype." >";
?>

 

gave me a half Black site, Lower half

 

<?php
   $images = array('image1.jpg', 'image2.png', 'image3.jpg');
?>

<a href="#"><img src="<?php bloginfo('stylesheet_directory');?>/images/<?php $images[array_rand($images, 1)]; ?>" alt="image file #2" width="125" height="125" /></a>

 

gave me a link saying image2

 

TT

Link to comment
Share on other sites

i am sorry for the previous code..

actually the code wil not work..

check the new code..

<?php

$dir="./";
$nimg="10";
$itype="jpg";

$rnumb=rand(1,$nimg);

echo "<img src=".$dir."".$rnumb.".".$itype.">";
?>

 

put the image numbers as 1.jpg,2.jpg,3.jpg......10.jpg

and place them in the same directory in which this code is there..

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.