tommytomato Posted November 24, 2009 Share Posted November 24, 2009 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 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 More sharing options...
Goldeneye Posted November 24, 2009 Share Posted November 24, 2009 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 More sharing options...
Deoctor Posted November 24, 2009 Share Posted November 24, 2009 use the below code <?php $dir="./"; $nimg="10"; $itype="jpg"; $bor="1"; $rnumb=rand(1,$nimg); echo ""<img src=".$dir."".$rnumb."".$itype." >"; ?> make the necessary changes to ur needs Link to comment https://forums.phpfreaks.com/topic/182752-ramdom-image/#findComment-964576 Share on other sites More sharing options...
tommytomato Posted November 24, 2009 Author Share Posted November 24, 2009 No luck with either source 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 More sharing options...
Deoctor Posted November 24, 2009 Share Posted November 24, 2009 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 More sharing options...
Yesideez Posted November 24, 2009 Share Posted November 24, 2009 Let's say your images are file_1.jpg, file_2.jpg, file_3.jpg and so-on... <img src="images/file_<?php echo mt_rand(1,3); ?>.jpg"> Link to comment https://forums.phpfreaks.com/topic/182752-ramdom-image/#findComment-964606 Share on other sites More sharing options...
tommytomato Posted November 26, 2009 Author Share Posted November 26, 2009 thanks guys for your help I'll get back to this later ON cheers TT Link to comment https://forums.phpfreaks.com/topic/182752-ramdom-image/#findComment-965810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.