Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Image Gallery - Latest Images on HomePage?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3
Go to End
Author Topic: 3931 Views
  • FireMe!
    Avatar
    Community Member
    74 Posts

    Image Gallery - Latest Images on HomePage? Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Image Gallery - Latest Images on HomePage? Link to this post

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

  • FireMe!
    Avatar
    Community Member
    74 Posts

    Re: Image Gallery - Latest Images on HomePage? Link to this post

    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!

  • FireMe!
    Avatar
    Community Member
    74 Posts

    Re: Image Gallery - Latest Images on HomePage? Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Image Gallery - Latest Images on HomePage? Link to this post

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

  • lawless
    Avatar
    Community Member
    33 Posts

    Re: Image Gallery - Latest Images on HomePage? Link to this post

    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?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Image Gallery - Latest Images on HomePage? Link to this post

    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.

  • boombox
    Avatar
    Community Member
    44 Posts

    Re: Image Gallery - Latest Images on HomePage? Link to this post

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

    3931 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.