Page 1 of 1

Random Banner MOD

PostPosted: Sat Sep 06, 2008 7:24 pm
Author: livewirestu
This mod displays a randomly selected banner for your site header. You can see this mod in action on this site if you refresh your page a couple of times (note that it does not work perfectly as I don't have many images - so the random number generator has a pretty good chance of generating the same number on each refresh)
This is such a small hack that it barely warrants a full modx package (also, some parts need to be adjusted as per preference).
Some parts of the php file are borrowed from Michaelo's sgp_get_rand_logo() function from SGP (in includes/sgp_functions.php).
So far, I have only written this mod for prosilver.

Here goes...
Create a new folder called 'banners' in styles/your_prosilver_based_style/theme/images and place any banner images you want in here.
Bear in mind that images will not be resized and so may stretch your site sideways if they are too large. What I have done for my banner images is make them all 750x170 pixels. Then at the right edge of each image, I have faded them out to black. Then I made the background colour of the header black too. The images now merge into the background colour seamlessly and as you stretch your browser out there is no distortion. If you reduce your browser window below 750 pixels wide, you will just get a scroll bar.

Copy this file into styles/your_prosilver_based_style/theme/images
(yes - we are putting a php file in the images directory :P)
random_banner.zip
styles/prosilver/theme/images
(723 Bytes) Downloaded 161 times


Open styles/your_prosilver_based_style/theme/colours.css
Find:
Code: Select all
.headerbar {
   background-color: #12A3EB;
   background-image: url("{T_THEME_PATH}/images/bg_header.gif");
   color: #FFFFFF;
}

Replace with:
Code: Select all
.headerbar {
   background: url("{T_THEME_PATH}/images/random_banner.php") no-repeat;
   color: #FFFFFF;
    background-color: #000000;
}

You can now use your artistic preference to alter the colours in this edit. Change 'color' to alter the colour of your site description text. Change background-color to alter the... erm... background colour.

Open styles/your_prosilver_based_style/theme/common.css
Find:
Code: Select all
/* Site description and logo */
#site-description {
   float: left;
   width: 70%;
}

Replace with:
Code: Select all
/* Site description and logo */
#site-description {
   float: left;
   width: 70%;
   height: 160px;
}

#site-description a {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}


Now change the height so that it is 10 pixels less than the height of your banner images (the 10 pixels is to account for the rounded corners at the top and bottom of panel).

Refresh all your caches and you are done ;)
Enjoy.
This mod works nicely in conjunction with my 'Header tidy up' mod, details of which will be posted soon (although you can see the effects of it on this site)
Cheers,
Stu

Re: Random Banner MOD

PostPosted: Wed Sep 17, 2008 4:47 pm
Author: TenEightyOne
I've just installed this on [url=http://www.worldleagueracing.com/forum] and it works really well!!!

Just one question; I currently have three gifs (sitelogo1, sitelogo2 and sitelogo3). #1 seems to be chosen five times more than 2 while 3 is rarely chosen at all.

Is there something I can do to average the chances of each logo being chosen... if that makes sense?

Re: Random Banner MOD

PostPosted: Wed Sep 17, 2008 5:11 pm
Author: livewirestu
Yeah the random number generator leaves a lot to be desired! It doesn't work too great with small numbers.
I'll have a look to see if I can improve it somehow.

Re: Random Banner MOD

PostPosted: Wed Sep 17, 2008 5:27 pm
Author: livewirestu
You could try removing the seed for the random number generator. It's quite hard to quantify if this works well with such small numbers involved. If you are choosing a random number between 1-3, chances are it will pick the same number twice or more in a row quite frequently.
Anyway, try this...
in styles/prosilver/theme/images/random_banner.php
Find:
Code: Select all
mt_srand((double)microtime()*1000001);

Replace with:
Code: Select all
//mt_srand((double)microtime()*1000001);


Let me know how that works out for you.

Re: Random Banner MOD

PostPosted: Wed Sep 17, 2008 7:37 pm
Author: TenEightyOne
A little better.

I'm going to make another seven or eight banners tonight to put in the banners folder so I'll see how it goes after that.

Thank you :D

Re: Random Banner MOD

PostPosted: Mon Feb 15, 2010 1:50 am
Author: n66x
this looks like a very interesting mod I want to install this but the instructions don't help cause i have the 'xandgrey' style installed..
do you think i can install this there or should i look for a mod especially made for that style?

thank you in advance,

Re: Random Banner MOD

PostPosted: Thu Mar 04, 2010 11:07 pm
Author: HelterSkelter
this will work with any theme