How to display a random image in this code?

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
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
•••
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
•••
Thanks, someone already gave me the same solution elsewhere. But much appreciated, anyway. :)
 
0
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Portfolio sites: new ways to sort, filter and group your domains
Your public portfolio page has a few new tools for visitors. Portfolio: Newest first The sort menu now has "Newest first". It shows the...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back