NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page How to display a random image in this code?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 10-13-2010, 07:24 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
kokopelli's Avatar
Join Date: Jul 2004
Location: USA
Posts: 555
kokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud of
 



Help! How to display a random image in this code?


Hope one of you PHP gurus can help me ...

In a WordPress theme, I want to change this code:
Code:
<?php if ( function_exists( 'get_the_image' ) ) { get_the_image(array( 'default_size' => 'thumbnail', 'image_scan' => true, 'default_image' => get_bloginfo( 'template_url' ) . '/images/default_thumbnail.png', 'width' => '100', 'image_class' => 'wp-post-image' )); } ?>
to something like
????: NamePros.com http://www.namepros.com/programming/682041-how-to-display-random-image-code.html
Code:
<?php if ( function_exists( 'get_the_image' ) ) { get_the_image(array( 'default_size' => 'thumbnail', 'image_scan' => true, 'default_image' => get_bloginfo( 'template_url' ) . '/images/default_thumbnail_0<?php echo rand(1,3)?>.png', 'width' => '100', 'image_class' => 'wp-post-image' )); } ?>
so a random image between 1 and 3 is displayed as thumbnail.

But my code doesn't work ... no image is displayed

Any idea how I should change it?
kokopelli is offline   Reply With Quote
Old 10-13-2010, 10:54 PM   #2 (permalink)
Qc4
NamePros Member
Join Date: Mar 2010
Posts: 124
Qc4 is on a distinguished road
 



The place where you put your rand() function is already inside PHP tags, so instead of opening new ones, you can just concatenate it with the rest of the string like this:

Code:
'default_image' => get_bloginfo( 'template_url' ) . '/images/default_thumbnail_0' . rand(1,3) . '.png',
__________________
DirectWWW - an OpenSRS reseller
Qc4 is offline   Reply With Quote
Old 10-13-2010, 11:22 PM THREAD STARTER               #3 (permalink)
NamePros Regular
 
kokopelli's Avatar
Join Date: Jul 2004
Location: USA
Posts: 555
kokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud ofkokopelli has much to be proud of
 



Thanks, someone already gave me the same solution elsewhere. But much appreciated, anyway.
kokopelli is offline   Reply With Quote
Reply

Tags
image, php, random, wordpress


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random frame display?? Biggie_mac Web Design Discussion 1 02-08-2006 07:19 AM
opensource programs for Linux OS dongan Free Resources 6 01-20-2006 08:54 PM
End of Year Special Plans - Perfect for Resellers! True 99.9% Uptime Guarantee! BlikWerk Web Hosting Offers 0 12-27-2005 03:24 PM
Random image background fishistheice Website Development 1 10-18-2005 04:20 AM

 
All times are GMT -7. The time now is 02:38 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger