Unstoppable Domains โ€” Get your daily AI drops report

How to display a random image in this code?

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
•••
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back