Social Network Advert Rotator

anonymous Hello gang,

If you sell bespoke advertising space on your Ning site then one of the key issues you’ll have as a publisher is giving advertisers equal time ‘above the fold’. This simple tip shows you how you can randomly rotate banner adverts in an HTML box.

First up, the html mark up, to be inserted in an HTML box on a custom page. In this example there are three banner ads of 300x100px. Here’s what we should start with:

<div class="SP_Sidebar_Ad_Rotate">
<li><a target="_blank" href=""><img src="*cFYsifPfTF1XxuOE8sm**53VHxk23/ad1.jpg" /></a></li>
<li><a target="_blank" href=""><img src="" /></a></li>
<li><a target="_blank" href=""><img src="" /></a></li>

You will need to replace the and the image source in each instance, and if you want more than three banners then all you need to do is add another List item – the code between <li> and </li>, so one banner add list code looks like this:

<li><a target="_blank" href=""><img src="" /></a></li>

Once you’ve got the links and banner images in place you will need the jQuery to rotate the list items. Here it is, to be placed in your Custom Code End of Page Code section:

xg.addOnRequire(function () {
x$(document).ready(function() {
x$(".SP_Sidebar_Ad_Rotate").html(x$(".SP_Sidebar_Ad_Rotate li").sort(function(){
    return Math.random()-0.5;

You will also want to add some css to the Design Studio Custom CSS section:

/*Side bar Ads*/
.SP_Sidebar_Ad_Rotate {
text-align: center;
display: none;

.SP_Sidebar_Ad_Rotate > li {
list-style: none!important;
margin-bottom: 5px;

You’ll notice that we’re hiding the ad units with css until the jQuery has done its magic once the page has loaded. This saves the ads ‘jigging’ about on the page while all the script loads.

Press save and try it out. Cool eh?



Richard Pettet
Follow me

Richard Pettet

I'm a professional website designer who specialises in Social Network and community website build and design work. Expert with Ning and BuddyPress.
Richard Pettet
Follow me

You might also like