How to display a random image in this code?

SpaceshipSpaceship
NamecheapNamecheap
Namecheap AuctionsNamecheap Auctions
Watch

kokopelli

Established Member
Impact
2
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/[color=#FF0000]default_thumbnail.png[/color]', 'width' => '100', 'image_class' => 'wp-post-image' )); } ?>

to something like
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/[color=#FF0000]default_thumbnail_0<?php echo rand(1,3)?>.png[/color]', '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?
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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',
 
1
Close
Thanks, someone already gave me the same solution elsewhere. But much appreciated, anyway. :)
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back