WordPress对此没有什么特别之处,只是一些简单的php:
// generate an array of numbers
$numbers = range( 1, 8 );
// shuffle the array in random order
shuffle( $numbers );
// use the first 4 values from the randomized array of numbers
echo eh_get_option( \'eh_slide_image_\' . $numbers[0] );
echo eh_get_option( \'eh_slide_image_\' . $numbers[1] );
echo eh_get_option( \'eh_slide_image_\' . $numbers[2] );
echo eh_get_option( \'eh_slide_image_\' . $numbers[3] );
如果有很多标记要重复,可以在循环中输出:
$numbers = range( 1, 8 );
shuffle( $numbers );
for ( $i = 0; $i < 4; $i++ ) {
echo eh_get_option( \'eh_slide_image_\' . $numbers[$i] );
}