random background image?

Permalink Browser Info Environment
Hi Chris,

How hard would it be to customize your theme to pick one picture at random from a subset of the files manager as the background image?

thanks!
W.

Type: Discussion
Status: New
wobeen
View Replies: View Best Answer
c5mix replied on at Permalink Best Answer Reply
c5mix
It would take some custom programming but shouldn't be that hard. First you should install this Fileset Attribute addon and created a new fileset attribute with the handle of bg_image_fileset.
http://www.concrete5.org/marketplace/addons/fileset-attribute/...

Then, just have the code in the header.php file that looks for the bg_image attribute look for the bg_image_fileset attribute instead. But you'll have to add in some "randomize" code so it only pulls in one random image instead of all. This might be of some help:
http://www.concrete5.org/community/forums/customizing_c5/display-ra...
wobeen replied on at Permalink Reply
wobeen
Hi Chris,

Sorry for the delay.
Your explanation was clear... it just took me while to understand that
$c->getAttribute('bg_image_fileset')

was returning a fileset ID and not the file set name itself.

Here the code I came up with, very much inspired by the indications given... Might be useful for others.

<script type="text/javascript">
$.backstretch("<?php
  if ($c->getAttribute('bg_image_fileset'))
   {  
   Loader::model('file_list');
   Loader::model('file_set');
   $fs = FileSet::getByID($c->getAttribute('bg_image_fileset'));
   $fileList = new FileList();
   $fileList->filterBySet($fs);
   $fileList->filterByType(FileType::T_IMAGE); 
   $files = $fileList->get(100,0); //limit it to 100 pictures
   $size = sizeof($files);
   $random = rand(0, $size - 1);
   $theFile = $files[$random];
   echo $theFile->getRecentVersion()->getRelativePath();

Thanks again for your help,
W.
c5mix replied on at Permalink Reply
c5mix
Great job! Thanks for posting this here!
coax replied on at Permalink Reply
coax
Hi I'm trying to insert as background image all images from a file set, I almost manage to do it, with the help of the previous script, my trouble is that I display all images from my fine manager not only my selected file set.
Loader::model('file_list');
               Loader::model('file_set');
               $fs = FileSet::getByID($c->getAttribute('photo-fond'));
               var_dump ($fs);
               $fileList = new FileList();
               $fileList->filterBySet($fs);
               $fileList->filterByType(FileType::T_IMAGE); 
               $files = $fileList->get(100,0); //limit it to 100 pictures
               $result = count($files);
               $result =$result - 1;
               for ($i = 0; $i <= $result; $i++) {
                  $theFile = $files[$i];
                  echo "<div><img src='".$theFile->getRecentVersion()->getRelativePath()."' /></div>";
.
my file set is called "photo-fond", can you help me please?
c5mix replied on at Permalink Reply
c5mix
Well, I think it's an issue with your file set handle. Pretty sure it can't have dashes in it - it has to have underscores for spaces, like photo_fond

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.