Randomising content

Randomising content

Paul B

XenForo moderator
Staff member
Brogan submitted a new resource:

Randomising content - rand()

Randomising content can be used in various ways, the most common of which is for header images and logos, or advertising banners.

This guide will explain how it can be done simply with one line of code (which ironically has taken a hundred lines of explanatory text).

For the purposes of this guide, we'll be adding a banner image in the Container header advertising position, which will randomly rotate between 5 different images.

Read more about this resource...
Nice ! Banner adverts typically have two components; the image ( which you have covered gracefully ) and the a href link to the site being advertised ... can those be added easily to the front of the code or does some other magic need to happen ?
If each banner has a different URL then it will require a different approach.

Not difficult but I'll put together another guide for that.
the man good job GIF by Playboy Fragrances

EDIT: I just tried it and it works like a charme.. really awesome thank you

is it possible to use this for google adsene and other ad affiliate sources ?

can we use as an example:

banner 1 and add google asdsense js script below
then use banner 2 and add amazon affilate ads
then use banner 3 for clickbank affilaite ads ?

would we just remove the <a href </a> and add the javascript code there ?
I just added this code below the an ad spot and it worked like miagic :)

<xf:set var="$banner.1">
   < google adsense code here>

<xf:set var="$banner.2">
    < amazon ad code here>

<xf:set var="$banner.3">
    < another affiliate ad code here>

{$banner.{{ rand(1,3) }}}

works great
Last edited:
Top Bottom