13
Jul
6
Working with banners
Most of the sites I work on are for corporate/business clients and there is not typically a lot of fancy motion graphics going on. I do like to ensure there is some dynamic element going on, just to provide a bit of interest and one of the simplest ways to achieve this is by some variation of the random/rotating banners scenario. Of course this could equally apply to other parts of the page, not just banner graphics.
Over the course of a few projects, trawling the SS forums and hacking together my own interpretations, I have ended up with a few different ways of doing this in SilverStripe.
A random rotating banner
This function gets a set of random banners from a specified folder - in this case BannerImages
In the template I then cycle through each of the images in the
folder marking up the HTML as required by the the excellent jQuery
cycle plugin (http://malsup.com/jquery/cycle/) which is what I use for the cycling of frames.
Note that I hide the banner images until jQuery loads, to get around
having all the images display at once right at the start. I then
initialise the jQuery Cycle plugin mentioned above inside the innit() function of the Page_Controller:
You should now have a lovely rotating banner using random images from a folder.
A single random Banner
You may also want to only have a single banner without the jQuery
rotation but still randomly picked. To achieve this forst create a new
function to just grab a single image:
Then in the template add the image as a background to the div (note. this will not validate as XHTML):
Variations on Image Getter functions
Here are a couple of slightly different way of retrieving the folder.
This function grabs a single image based on it's parent folder's ID:
While this function uses the folders name:
or more usefully you can pass in the folder name:
Getting the banner from the top level parent
Often
you may want to only set the banner for the top level 'section' page
and have it passed down to all it's children. The simlest way to do
this is by using the level(1) function on the current page and then
calling the appropriate function on the top level page like so:
About the Author
Name: Nick Jacobs
Website: http://nickjacobs.net.nz
Nick is a freelance designer/developer based in Gisborne, New Zealand
Comments (6)
-
nice one nick :)
Posted by mike mcvey, 10/05/2010 5:59pm (3 months ago)
-
Hi,
Hoping you can help me... I am trying to setup some static banners on our intranet that point to internal pages. Basically they are images that send you to another page on the site. I've set up the CMS so there is a new 'Banner' tab where a user can select an image to display, but curently I'm using a textbox for the link. The content editors have to type in the hyperlink which they don't like. Within the WYSIWYG for HTML fields there is the hyperlink popup where you can select a 'Page on the site'. Can I link this to my textfield? Or is there some other way of calling this functionality outside of the WYSIWYG?
Thanks!Posted by AJ, 30/04/2010 3:44am (3 months ago)
-
How can I make this slide show "not" random?
ie. just using a Cycle plugin that calls images from a specified folder.
CheersPosted by Ben, 09/12/2009 3:38pm (8 months ago)
-
Hi Chris
I have adjusted the code and text to hopefully make this a little clearer. Thanks for pointing it out :)
AramPosted by Aram , 03/08/2009 6:02am (12 months ago)
-
Thanks! I've been looking for something like this for ages. I have one persisting problem though.
Where does this code go?
$(document).ready(function(){
$('#bannerimgs').cycle({ delay: 5000, speed: 2000 });
$('#bannerimgs').show();
});
Do I call it in the PHP as a custom code? Or do I place it in the head of my .ss file like I would with a normal HTML site?
I've tried both, and neither seems to work. I'm getting desperate now :(Posted by Chris, 01/08/2009 12:19pm (12 months ago)
-
Thanks. I was thinking about this but didn't want to tackle it in SS since I'm still just wrapping my head around the whole SS concept and have bigger more pressing problems to solve. I'll have to try this out though...
Posted by lawless, 13/07/2009 11:54am (1 year ago)
RSS feed for comments on this page RSS feed for all comments