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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Image Gallery - Latest Images on HomePage?


Go to End
Reply


23 Posts   3989 Views

Avatar
FireMe!

Community Member, 74 Posts

15 July 2009 at 6:24am

Hi

I'm trying to add the latest 5 images to the homepage of a site, I don't really know how to do it. Is this feature already in the image gallery module some where? if not any ideas how to get this to work?

Thanks in advance

FireMe

Avatar
UncleCheese

4085 Posts

15 July 2009 at 7:02am

function LatestImages()
{
return DataObject::get("ImageGalleryItem", null, "Created DESC", null, 5);
}

Avatar
FireMe!

Community Member, 74 Posts

16 July 2009 at 5:08am

thanks for the fast reply unclecheese, but I have one more question, I think :-)

firstly i put this code in my template

<% control LatestImages %>
<li style="height:{$Top.ThumbnailSize}px;width:{$Top.ThumbnailSize}px;">
<a id="ViewLink-$ID" rel="$RelAttr" class="$ClassAttr" title="$Caption" href="$ViewLink"><img src="$ThumbnailURL" alt="$Title"/></a>
</li>
<% end_control %>

but it did not seem to display the image, just a link that does not work. So I tried this code

<% control LatestImages %>
$Thumbnail
<% end_control %>

Which worked, but I could not figure out how to get a link to it that worked, also how would I control the the thumbnail size.

thanks in advance

FireMe!

Avatar
FireMe!

Community Member, 74 Posts

20 July 2009 at 5:26am

all I want to do is have it use the lightwindow, any one know how to?

Avatar
UncleCheese

4085 Posts

20 July 2009 at 6:05am

Just include the required javascript and use the markup that it requires. The Lightwindow documentation should explain how to do that.

Avatar
lawless

Community Member, 33 Posts

5 August 2009 at 4:19pm

I found this post while searching on how to display ImageDataObjectManager items on the home page. I got it working using the code examples in this post.

I used UncleCheese's code snippet:

function LatestImages()
{
return DataObject::get("ImageDataObjectManagerItem", null, "Created ASC", null, 2);
}

on mysite/code/HomePage.php

and added this to themes/blackcandy/templates/layout/HomePage.ss

<% control LatestImages %>
      <img src="$Attachment.URL" alt="$field1" title="$field1 - $field2" /><br />
      $field1<br />$field2<br />$field3
      <% end_control %>

Is this the best way to do this using an ImageDataObjectManager item? What are the NULL fields in the array for?

Avatar
UncleCheese

4085 Posts

6 August 2009 at 1:59am

Yup, that's the best way to do it. I'm going to be adding in a LatestImages function to the image_gallery core so this will be a lot easier. I'll also be adding a publicly accessible method includeUI() so you can get your lightbox UI anywhere on your site.

The null values are for the filter and join arguments.

Avatar
boombox

Community Member, 44 Posts

19 August 2009 at 1:28pm

Hi Uncle Cheese
Will this function enable the latest images from a single albumto be displayed on another page (e.g homepage?)
I was working with a Image Gallery Widget
http://www.silverstripe.org/dataobjectmanager-module-forum/show/265603#post265603
I can get latest images shown - but from all albums
I am trying to make a widget that you can configure to show a featured albums images- I am have trouble limiting the number of images shown (referenced as Gallery Items)

Code I am using in widget
function LatestGallery() {
      $album = DataObject::get_one("ImageGalleryAlbum", "FeaturedAlbum = 1");
      //Debug::show($album);
      return $album;
   }

Template code

<% control LatestGallery %>
      <div id="latestEvents">
         <div class="title">
            <h2>Latest Events</h2>
            <h3><a class="$LinkingMode" href="$Link" title="$AlbumName">$AlbumName</a></h3>
         </div>
            <ul class="latestPictures">
               <% control GalleryItems %>
                  <li style="height:{$Top.ThumbnailSize}px;width:{$Top.ThumbnailSize}px;">
                        <a id="ViewLink-$ID" rel="$RelAttr" class="$ClassAttr" title="$Caption" href="$ViewLink">$Image.SetWidth(100)</a>
                  </li>
               <% end_control %>
            </ul>
      </div>
      <% end_control %>

Go to Top