I have the following code that I am using to randomly display PHP widgets from a folder:
<?php
function random_widget($dir = 'wp-content/themes/zonza/elements')
{
$files = glob($dir . '/*.*');
$file = array_rand($files);
return $files[$file];
}
?>
<?php include random_widget();?>
<?php include random_widget();?>
<?php include random_widget();?>
random_widget(); outputs a URL, which I then use in the include function to display the widget.
The code randomly chooses between 6 php files and displays one randomly. I include it 3 times to get 3 widgets. However, I get the same widget displayed more than once sometimes.
What can I do to modify the code to prevent this from happening?