Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Image gallery

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2791 Views
  • kpax
    Avatar
    Community Member
    1 Post

    Image gallery Link to this post

    As far as I know there's no image gallery module available for SilverStripe yet, is there?
    Would anyone know, in what way something like a gallery with custom fields for title, description, etc. could be created anyway for the time being?

    thanks a lot

  • MaryE
    Avatar
    Community Member
    2 Posts

    Re: Image gallery Link to this post

    I too am intersted in such a module. I was thinking of building a page type -- done so for other CMS', but a module would be nice for mass uploading (from a zip), EXIF/IPTC/XMP extraction, thumbnail mgmt, etc. Just downloaded the CMS, so it may be sufficient to build page type.

    M.

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Image gallery Link to this post

    The most basic gallery can be made using two custom page types:

    GalleryHolder
    GalleryPage

    You first create a Gallery Holder in SilverStripe which can be used to show all photos as a landing page (if desired), then under the Gallery Holder you create Gallery Pages which are the individual gallery items.

    Example:

    GalleryHolder.php:
    ===============

    <?php

    class GalleryHolder extends Page {
       
    // gallery pages are the default page to be created under a holder
    static $default_child = "GalleryPage";

    // only gallery pages are allowed under a holder section
       static $allowed_children = array("GalleryPage");
       
       /**
        * Return the gallery pages with a limit you can set in template
    * default is 5 if nothing set
        */
       function GalleryItems($limit = 5) {
          return DataObject::get("GalleryPage","`ParentID` = '{$this->ID}'", "", "", $limit);
       }
    }

    GalleryPage.php:
    ==============

    <?php

    class GalleryPage extends Page {

    // define your database fields here - for example we have author
       static $db = array(
          "Author" => "Varchar(100)"
       );

    // define image class relationships here (see Photo_GalleryImage class below)
       static $has_one = array(
          "Image" => "Photo_GalleryImage",
       );
       
       function getCMSFields($cms) {
          $fields = parent::getCMSFields($cms);
          $fields->addFieldToTab("Root.Content.Main", new TextField("Author","Photo author"));
    $fields->addFieldToTab("Root.Content.Main", new ImageField("Image", "Photo"));
          return $fields;
       }
    }
       
    class GalleryPage_Image extends Image {
       
    // define different GD functions to resize uploaded photos, see the GD page in the SilverStripe documentation for different functions for resampling

       function generateThumbnail($gd) {
          $gd->setQuality(90);
          return $gd->resizeByWidth(288);
       }
       function generateNormal($gd) {
          $gd->setQuality(90);
          return $gd->resizeByWidth(395);
       }
    }

    ?>

    You can then define some templates for these page types:

    GalleryHolder.ss:
    =============

    <div id="Gallery">
       <% if GalleryItems %>
          <ul class="galleryList">
    <!-- define limit in brackets -->
          <% control GalleryItems(10) %>
             <li>
                <h3>$Title</h3>
                <img src="$Image.Thumbnail.URL" alt="$Title photo" />
                <p class="details">Added on $Created.Nice<% if Author %> by $Author<% end_if %></p>
             </li>
          <% end_control %>
          </ul>
       <% end_if %>
    </div>

    GalleryPage.ss:
    ============

    <div id="Content">
       <h2>$Title</h2>
       <img src="$Image.Thumbnail.URL" alt="$Title photo" />
       <p class="details">Added on $Created.Nice<% if Author %> by $Author<% end_if %></p>   
    </div>

    You can get even fancier with pagination - ie. a results block with << Prev 1 2 3 Next >> etcetera, but this would be a good starting point if you're interested in making a gallery.

  • MaryE
    Avatar
    Community Member
    2 Posts

    Re: Image gallery Link to this post

    Thanks Sean for a quick start.

    Am familiar with GD and you give me a good start with the classes to extend. I have also used phpThumb for display caching and might consider that if I get this thing going ...

    However still having trouble installing, trying to follow a few other threads that are experiencing similar probs. (I've got XAMPP on local machine, figure 5.2 might be culprit, also had to muck w/ mySQL acct settings but got through that one).

    M.

    PS - not intending to start a separate thread on this, but it might be easier to give the option to have the admin set up the target DB, might save time in some cases. Still looks to be a great cms though, hope to get through this stuff.

  • The Frenchy
    Avatar
    Core Development Team
    40 Posts

    Re: Image gallery Link to this post

    The version 0.2 has been released. check this.

    2791 Views
Page: 1
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.