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

Limit Control??**SOLVED**


Go to End
Reply


4 Posts   1115 Views

Avatar
ambient

Community Member, 123 Posts

23 April 2013 at 1:29am

Edited: 23/04/2013 4:19am

Hi All,

I have a gallery which I am using DataObject Manager to add multiple images and it all works fine.

However I want to display the first 3 images of the gallery on another page.

I've searched for a solution and tried figuring it out myself but have had no success.

I can get the images to appear on the other page but it shows all of them instead of just 3.

This is my code that I have tried

<% if GalleryImages %> 
	<% control GalleryImages(3) %> 
               <div class="listing_pic">
			<a href="$Link"><img src="$MyGalleryImage.GroupThumb.URL" alt="<% sprintf(_t("IMAGE","%s image"),$Title) %>" /></a>
               </div>
          <% end_control %> 
<% end_if %>

I also have tried

public function GalleryImages($Limit = 3){

return DataObject::get("GalleryImage", "ParentID = $this->ID", Null, Null, $Limit);

}

Any help would be appreciated, Thanks

** EDIT - I am using ss 2.4

Avatar
ambient

Community Member, 123 Posts

23 April 2013 at 7:40pm

Nobody has any ideas on this?

I thought it would be straightforward enough to do but just haven't figured out what I'm doing wrong :(

Avatar
Lexandclo

Community Member, 36 Posts

30 April 2013 at 7:28am

Hi

Maybe try this

function NewestGalleryImages($num=3) {
$GalleryImages = DataObject::get_one("GalleryImage");

return ($GalleryImages) ? DataObject::get("GalleryImage", "", "ParentID = $this->ID", "", $num) : false;

let me know

Darren

Avatar
ambient

Community Member, 123 Posts

1 May 2013 at 9:44pm

Thank you Darren,
I had some help from IOTI here http://www.silverstripe.org/general-questions/show/23540#post321545

And this got it working in the end

public function GImages($limit = 3){ 
$filter = 'BelongToProductID =' . $this->ID; //filter 
if($images = DataObject::get('GalleryImage', $filter, $sort='', $join='', $limit="0,$limit")){ 
return $images; 
} 
}