Hi folks,
I have a problem with getting some random images from the latest galleries.
I would like to have in my GalleryHolder template shown structure as this:
<h2>Gallery Title no 1</h2>
<img no=1>
...
...
<img no=5>
<p>$Content description</p>
<h2>Gallery Title no 2</h2>
<img no=1>
...
...
<img no=5>
<p>$Content description</p>
etc....
I made some code in my GalleryHolder.php
function LatestGallery($limit=3, $limitIMG=5) {
$sqlQuery = new SQLQuery();
$sqlQuery->select = array("Gallery.ID AS GalleryID, Gallery.FolderID, File.FileName,SiteTree_Live.URLSegment, SiteTree_Live.Title");
$sqlQuery->from = array("GalleryPage Gallery
LEFT JOIN SiteTree_Live ON SiteTree_Live.ID = Gallery.ID
LEFT JOIN File ON File.ID = Gallery.FolderID");
$sqlQuery->where = array();
$sqlQuery->orderby = "Gallery.ID DESC";
$sqlQuery->limit = $limit;
$rawSQL = $sqlQuery->sql();
$result = $sqlQuery->execute();
$doSet = new DataObjectSet();
foreach($result as $k => $row) {
$FolderID = $row['FolderID'];
$Filename = $row['FileName'];
$URL = $row['URLSegment'];
$Title = $row['Title'];
$sqlQuery2 = new SQLQuery();
$sqlQuery2->select = array("*");
$sqlQuery2->from = array("File");
$sqlQuery2->where = array("ParentID=$FolderID");
$sqlQuery2->orderby = "RAND()";
$sqlQuery2->limit = $limitIMG;
$rawSQL2 = $sqlQuery2->sql();
$result2 = $sqlQuery2->execute();
$ArraySet['URL'] = $URL;
$ArraySet['Title'] = $Title;
foreach($result2 as $a => $v) {
$ArraySet["IMG_$a"] = $v['Filename'];
}
$doSet->push(new ArrayData($ArraySet));
}
return $doSet;
}
In my template I use <% control LatestGallery %> to get access to this DataObject.
However, I have one big problem, and I cannot find a nice solution:
- in my template I have an url to the original image, but how to manage thumbnail creation from the template. I would like to have image 120x80px shown in my template instead of original image 800x600px.
My environment: SS 2.3.2 + Gallery Module.
thx in advance