When I placed the exclusive WordPress Theme Discount banners on the WP Mods sidebar I used some basic PHP in order to shuffle the banners around. This ensured that all banners got equal exposure.
I’d like to share with you all today the simple code I used to achieve this banner rotation. The code will not track impressions or click throughs; all it does is ensure that all entries in the array are shuffled every time the page is loaded. You can place any code within each array (e.g. PHP, CSS, HTML etc).
In the example below I have called the array string $banner_rotate. You could change this to anything you want e.g. $textshuffle, $banshuff etc. Also, make sure that you use the single quotation mark (‘) within the array instead of double quotations (“).
<?php $banner_rotate[0]="<a href='http://www.site.com'><img src='http://www.site.com/banner0.png' /></a>"; $banner_rotate[1]="<a href='http://www.site.com'><img src='http://www.site.com/banner1.png' /></a>"; $banner_rotate[2]="<a href='http://www.site.com'><img src='http://www.site.com/banner2.png' /></a>"; $banner_rotate[3]="<a href='http://www.site.com'><img src='http://www.site.com/banner3.png' /></a>"; shuffle($banner_rotate); for ($i=0;$i<=3;$i++){ echo $banner_rotate[$i]; } ?>
The shuffle function mixes the array around and the final piece of code ensures that all entries in the array are displayed on your site. Adding more entries into the array is simple; you just need to make sure you increment $banner_rotate[3] to $banner_rotate[4] and then $banner_rotate[5] and so on. Remember to edit the for statement at the end to reflect the number of entries in the array (e.g. change $i<=3 to $i<=5 etc).
If you are unsure about any aspect of this, please let me know.
Thanks,
Kevin






this:
$banner_rotate_size = count( $banner_rotate );
for ( $i = 0; $i < $banner_rotate_size; $i++ ) {
// your code goes here
}
and this:
$banner_rotate[] = 'list';
$banner_rotate[] = 'list';
$banner_rotate[] = 'list';
$banner_rotate[] = 'list';
// much much more items .....
would be more universal and more clear and more easier to maintain.
Good tip though.
- spam
- offensive
- disagree
- off topic
Like