Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

Include all images from folder


Go to End
Reply


10 Posts   3107 Views

Avatar
freewolny

Community Member, 12 Posts

16 January 2009 at 12:31am

Hi!

How can I include all images uploaded to a folder?

Avatar
Carbon Crayon

Community Member, 598 Posts

16 January 2009 at 1:02am

Edited: 16/01/2009 8:30am

Hi Freewolny

You need to make a function in your page controller that grabs all the images from the folder and returns them. Something like this:

function GetImages(){

return DataObject::get("Image", "ParentID = $FolderID");

}


Then in your template:

<% control GetImages %>
<img src="$URL" alt="$Name" >
<% end_control %>

Avatar
freewolny

Community Member, 12 Posts

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?
And
Is it possible to publish all the photos from 3 different folders?

Avatar
Carbon Crayon

Community Member, 598 Posts

16 January 2009 at 3:07am

Edited: 16/01/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");

Avatar
freewolny

Community Member, 12 Posts

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!

Avatar
Carbon Crayon

Community Member, 598 Posts

16 January 2009 at 6:14am

Thanks freewolny, your welcome :)

Avatar
freewolny

Community Member, 12 Posts

16 January 2009 at 7:46am

Hello again,
It looks like I need some more help.
I try to do it like this:

function GetImages(){

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...

Avatar
Carbon Crayon

Community Member, 598 Posts

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!

Go to Top