5514 Posts in 1733 Topics by 1219 members
Page: 1 2
|Go to End||Next >|
16 January 2009 at 12:31am
How can I include all images uploaded to a folder?
16 January 2009 at 1:02am Last edited: 16 January 2009 8:30am
You need to make a function in your page controller that grabs all the images from the folder and returns them. Something like this:
return DataObject::get("Image", "ParentID = $FolderID");
Then in your template:
<% control GetImages %>
<img src="$URL" alt="$Name" >
<% end_control %>
16 January 2009 at 2:54am
Thank you for your reply. I find it very useful. Unfortunately, I need some more information:
Where and how to define (to name) the folder that contains the pictures to be grabbed?
Is it possible to publish all the photos from 3 different folders?
16 January 2009 at 3:07am Last edited: 16 January 2009 8:31am
The folder is identified by it's ID, so in the line DataObject::get("Image", "FolderID = $FolderID"); we need to replace $FolderID with the actual numeric ID of the folder you want to grab the images from.
The esiest way to do this is to just hard code the number in there. To get the ID of the folder you can either use phpMyAdmin and look into the 'files' table, or you can go to the admin area of the CMS and open the 'Files & Images' tab. Then Hover over the folder and look at your status bar (bottom left of the browser), you will see the URL of the folder and on the end of it will be a number, this is the folder ID.
The second way to do this is dynamically with another database call. So you could do something like this in your function:
$FolderID = DataObject::get_one("Folder", "Name = SomeFolder")->ID;
Then use $FolderID in the next DB call to the images as before.
To get more than one folders images you can use the mysql OR operator to do something like this:
return DataObject::get("Image", "ParentID = $Folder1 OR ParentID = $Folder2 OR ParentID=$Folder3");
16 January 2009 at 6:10am
Once again many thanx.
Your suggested easiest way (with hard coding the number) is enough for me.
Have a nice day aram!
16 January 2009 at 6:14am
Thanks freewolny, your welcome
16 January 2009 at 7:46am
It looks like I need some more help.
I try to do it like this:
return DataObject::get("Image", "FolderID = 1");
and I have an error:
[User Error] Couldn't run query: SELECT `File`.ID, `File`.ClassName, `File`.Created, `File`.LastEdited, `File`.Name, `File`.Title, `File`.Filename, `File`.Sort, `File`.ParentID, `File`.OwnerID, `File`.PopupWidth, `File`.PopupHeight, `File`.Embed, `File`.LimitDimensions, `File`.Caption, `File`.AlbumID, `File`.ID, if(`File`.ClassName,`File`.ClassName,'File') AS RecordClassName FROM `File` WHERE (FolderID = 1) AND (`File`.ClassName IN ('Image','Image_Cached')) ORDER BY Name Unknown column 'FolderID' in 'where clause'
In the next step I would like to create 3 separate functions that get images from 3 different folders and include them to diffferent div's. The problem is this error above...
16 January 2009 at 8:30am
oops my bad! Its supposed to be 'ParentID = 1' rather than 'FolderID = 1'
I have corrected my posts above.
Sorry about that!
Page: 1 2
|Go to Top||Next >|