How can I create a block with random images from subfolders?
For example I have files/albums/Group1, files/albums/Group2 and files/albums/Group3 each group folder has subfolders. What I want to do is create a random images block with images from all folders in files/albums/Group1 for example.

Comments

helge_t’s picture

Hi, as I needed this feature, too, I solved this with a small piece of code:

$path = '/path/to/your/albums/folder';
$i = 0;
if ($handle = opendir($path)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && is_dir($path . '/' .$file)) {
            $directories[$i] = "$file";
            $i += 1;
        }
    }
    closedir($handle);
}
$randomgallery =  $directories[rand(0,$i-1)];
echo "[bg|" . $randomgallery . "|1||random|1|#aaaaaa]";

For custom PHP code to work you need to enable module "PHP filter".
And within the "Input format" settings you have to enable "Brilliant Gallery Tag" for input format "PHP code".

Please note: I am not a professional PHP coder - so if anything in this code should not be correct und insecure, please correct it here.
Best regards
Helge

H3rnand3z’s picture

I can use this, The only suggestion would be to check the file extension.

Thank You