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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

SS3: gallery and slider


Reply

3 Posts   675 Views

Avatar
aurum

27 July 2012 at 9:50pm (Last edited: 27 July 2012 10:03pm), Community Member, 5 Posts

Is there a gallery module or any module for making a slider? I really need a slider and a gallery to my site. Help, please!

Avatar
Craftnet

27 July 2012 at 10:53pm (Last edited: 27 July 2012 10:55pm), Community Member, 58 Posts

Hi,

Build yourself slider and a gallery - you can better customize it for your requirements.
I usually use the slider: bxSlider,
To the gallery: fancybox,

For example to gallery use:

<?php
class Gallery extends DataObject
{
static $db = array (

);

static $has_one = array (
   'Photo' => 'Image',
'HomePage' => 'HomePage' //Page where the gallery will be available
);
   
   
   function getCMSFields() {
return new FieldSet(
new UploadField('Photo')
);
}
}

And in Page from has_many (in my example HomePage)

<?php
class HomePage extends Page {

(...)

static $many_many = array(
'Gallerys' => 'Image'
);

public function getCMSFields() {
   $fields = parent::getCMSFields();

(...)

      $fields->addFieldToTab('Root.Gallery', new UploadField('Gallerys', 'Gallery'));
return $fields;   
}
}

class HomePage_Controller extends Page_Controller {   
    public function init() {
      parent::init();

      Requirements::javascript('https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');
      Requirements::javascript("mysite/javascript/jquery.bxSlider.min.js");
      Requirements::javascript("mysite/javascript/option.bxSlider.js"); //option for bxslider
   }
}

in template use

<% loop Gallerys %>
   <a rel="gallery" href="$URL">$SetWidth(80)</a>
<% end_loop %>

Sorry for my bad English

Avatar
aurum

28 July 2012 at 2:22am Community Member, 5 Posts

Thank you, Craftnet!
Unfortunately, I'm not a PHP programmer, but I'll try your method.