Jump to:

794 Posts in 409 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » Modifying Gallery Widget : Latest Pictures

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 465 Views
  • Fraser
    Avatar
    Community Member
    46 Posts

    Modifying Gallery Widget : Latest Pictures Link to this post

    I need to modify the Gallery>Latest Pictures widget slightly to pass through a thumbnail url and a full image URL. I want them both scaled to a certain size;

    I have managed to get the URL for the original image but would like your guys' help with getting a resized image in the same way that the Thumbnail is resized

    LatestPicturesWidget.php:

    function Pictures() {
    Requirements::css("widgets_gallery/LatestPicturesWidget.css");
          $nrtoshow = (0<$this->NumberToShow) ? $this->NumberToShow : $this->defaults["NumberToShow"];
          $pictures = DB::query("SELECT f.`ID`, f.`Filename`, f.`Name`, f.`Title`, s.`URLSegment` FROM `gallerypage_live` g LEFT JOIN `sitetree_live` s ON g.`ID` = s.`ID` LEFT JOIN `file` f ON f.`ParentID` = g.`FolderID` WHERE f.`ClassName` = 'Image' ORDER BY f.`Created` DESC LIMIT 0,$nrtoshow;");
       $thumbnails = new DataObjectSet;
       foreach ($pictures as $picture){
           $picture["GalleryLink"] = Director::baseURL().$picture["URLSegment"];
           $thumbnail = new Image($picture);
           $thumbnail = $thumbnail->getFormattedImage( "PaddedImage", $this->ThumbnailWidth, $this->ThumbnailHeight);
           $thumbnail->setField("GalleryLink", Director::baseURL().$picture["URLSegment"]);
       
           $thumbnail->setField("MainLink",Director::baseURL().$picture['Filename']);
                
           $thumbnail->setField("Name", $picture["Name"]);
           $thumbnail->setField("Title", $picture["Title"]);
              $thumbnails->push($thumbnail);
              
       }
       unset($pictures);
          return $thumbnails;
       }

    LatestPicturesWidget.ss:

    <% control Pictures %>
          <li>
             <!--<a href="$GalleryLink"><img src="$Filename" alt="" title="$Title" class="LatestPicturesImage" /></a>-->
             <a href="$MainLink" class="fancybox" rel="group" title="$Title"><img src="$Filename" alt="" title="$Title" class="LatestPicturesImage" /></a>

          </li>
       <% end_control %>

    Thanks in advance

  • Fraser
    Avatar
    Community Member
    46 Posts

    Re: Modifying Gallery Widget : Latest Pictures Link to this post

    Solved

    function Pictures() {
    Requirements::css("widgets_gallery/LatestPicturesWidget.css");
          $nrtoshow = (0<$this->NumberToShow) ? $this->NumberToShow : $this->defaults["NumberToShow"];
          $pictures = DB::query("SELECT f.`ID`, f.`Filename`, f.`Name`, f.`Title`, s.`URLSegment` FROM `gallerypage_live` g LEFT JOIN `sitetree_live` s ON g.`ID` = s.`ID` LEFT JOIN `file` f ON f.`ParentID` = g.`FolderID` WHERE f.`ClassName` = 'Image' ORDER BY f.`Created` DESC LIMIT 0,$nrtoshow;");
          $largeImage = new DataObjectSet;
       $thumbnails = new DataObjectSet;
       foreach ($pictures as $picture){
          
          $largeImage = new Image($picture);
          $largeImage = $largeImage->getFormattedImage( "PaddedImage", 632, 418);

           $picture["GalleryLink"] = Director::baseURL().$picture["URLSegment"];
           
           $thumbnail = new Image($picture);
           $thumbnail = $thumbnail->getFormattedImage( "PaddedImage", $this->ThumbnailWidth, $this->ThumbnailHeight);
           $thumbnail->setField("GalleryLink", Director::baseURL().$picture["URLSegment"]);
       
           $thumbnail -> setField("MainLink",$largeImage);
                
           $thumbnail->setField("Name", $picture["Name"]);
           $thumbnail->setField("Title", $picture["Title"]);
              $thumbnails->push($thumbnail);
              
       }
       unset($largeImage);
       unset($pictures);
          return $thumbnails;
       }

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