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
https://forums.phpfreaks.com/topic/182752-ramdom-image/
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
https://forums.phpfreaks.com/topic/182752-ramdom-image/#findComment-964569
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
https://forums.phpfreaks.com/topic/182752-ramdom-image/#findComment-964582
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
https://forums.phpfreaks.com/topic/182752-ramdom-image/#findComment-964605
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.