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.
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 |
Hi Chris,
Sorry for the delay.
Your explanation was clear... it just took me while to understand that
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.
Thanks again for your help,
W.
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();
Viewing 15 lines of 19 lines. View entire code block.
Thanks again for your help,
W.
Great job! Thanks for posting this here!
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.
.
my file set is called "photo-fond", can you help me please?
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?
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
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...