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.

Archive

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

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

Displaying latest gallery images on the homepage


Reply

2 Posts   972 Views

Avatar
bones

6 October 2008 at 9:14pm Community Member, 104 Posts

Hi,

On my homepage, I have the 3 newest articles from my "news" and "blog" pages, but would also like to show the 3 newest pages from my gallery.

class NewHomePage_Controller extends Page_Controller {
   function LatestNews() {
      $news = DataObject::get_one("ArticleHolder");
      return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", 3) : false;
   }
}

However the method used above (taken from the tutorials on the Silverstripe website) simply doesn't work for the GalleryPages.

Any suggestions

Thanks (as always)

Avatar
erwanpia

6 October 2008 at 9:41pm Community Member, 63 Posts

Hi I have started working on this : the GalleryFolder page type is an example of gallery images being displayed on a parent page. The only problem with this is that the ChildGalleries function gives a hard job to the server when images have not been resized yet by sub galleries. Complete package with template is available on my [url=http://www.webmasterbulletin.net/2008/09/silverstripe-gallery-jquery-module/307]jquery gallery module implementation[/url]

/**
* Defines the GalleryFolder page type
*/
class GalleryFolder extends Page {
static $db = array(
);
static $has_one = array(
);

// static $allowed_children = array('GalleryPage', '');
}

class GalleryFolder_Controller extends Page_Controller {

function ChildGalleries( ) {
$ChildGalleries = DataObject::get("GalleryPage", "ParentID = " . $this->ID);
//? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false
return ($ChildGalleries) ;
}
function init() {
      parent::init();          
      Requirements::css("gallery/css/Gallery.css");
}
}

template

<div id="ImageGalleryFolder"><ul>
<% control ChildGalleries %>
   <li><a href="$Link" alt="$Parent.Title">
<% if CurrentGalleryItems %>

         <% control GalleryItems(1) %>
      
   <img src="$ThumbnailURL" alt="$Parent.Title" title="$Parent.Title" />
   <br>$Parent.MenuTitle
   
                  
         <% end_control %>

<% end_if %>
</a> </li>
<% end_control %>
</ul></div>