Page 1 of 1

Randomise Banner Graphic

Posted: Tue Jan 22, 2008 4:52 am
by Andrew Prior
Hi all.
I have the following code from the Layout: Top menu + 2 columns stylesheet in v 1.2.3 Black Rock


div#header h1 a {
/* you can set your own image here */
  background: #385C72 url(uploads/images/banners/banner_1.jpg) no-repeat 0 1px;
  display: block;
  height: 87px;            /* adjust according your image size */
  text-indent: -999em;  /* this hides the text */
  text-decoration:none; /* old firefox would have shown underline for the link, this explicitly hides it */
}

Is there anyway I can randomise the choice of that image. I have a couple of ramdomising methods, but the
url(uploads/images/banners/banner_1.jpg)
fouls them up.

Andrew

Re: Randomise Banner Graphic

Posted: Thu Jan 24, 2008 12:10 am
by Dr.CSS
Have you looked in forge for a random image module?...

Re: Randomise Banner Graphic

Posted: Thu Jan 24, 2008 2:09 am
by Andrew Prior
Yes, doesn't work in this context unfortunately

Re: Randomise Banner Graphic

Posted: Thu Jan 24, 2008 2:14 am
by calguy1000
Using this thread (in the tips & tricks forum):  http://forum.cmsmadesimple.org/index.php/topic,15706.0.html

You could do something like this:

Code: Select all

{capture assign='num'}{1|rand:10}{/capture}{* generate a random number between 1 and 10, assign it to 'num *}
<div id="background" style="background #385C72 url(uploads/images/banners/banner_{$num}.jpg) no repeat 0 1px"></div>

Re: Randomise Banner Graphic

Posted: Thu Jan 24, 2008 7:12 am
by hexdj
Try image rotator by Alby

You can't use it for bg images, but it will randomize 's

Re: Randomise Banner Graphic

Posted: Fri Jan 25, 2008 4:09 am
by Andrew Prior
Hi Calguy.
I use your random image code a lot; it's extremely useful, thanks.
But it will not work in this location. It seems not to parse the code when I put {$num} in place of the file name. There is simply no image appears. I've assumed that this is because it is in  a stylesheet rather than in a template.
Andrew

Re: Randomise Banner Graphic

Posted: Fri Jan 25, 2008 4:17 am
by calguy1000
if you look at the example above.... I'm using doing it all in HTML by passing an additonal style attribute on the div.  and smarty will work there.