Resource icon

Display A Random Banner

Jake Bunce

Well-known member
Jake Bunce submitted a new resource:

Display A Random Banner (version 1.x) - Template code to define and randomize banners.

Here is some template programming to define and randomize your banners:

This code works in any template. For randomizing banner advertisements you are probably working in one of the ad_ templates. For example:

Admin CP -> Appearance -> Templates -> ad_above_content

Use this code:

Rich (BB code):
<xen:comment>DEFINE AND RANDOMIZE YOUR BANNERS</xen:comment>

<xen:set var="$banners.1">banner one</xen:set>
<xen:set...

Read more about this resource...
 
Awesome, great tutorial. Could you tell me what the conditional is for just the homepage?
 
Thanks for the share Jake. I have a stupid question. Stupid because I'm sure I could login to my AdminCP and see for meself LOL - But can I input javascript like so:


Code:
<xen:set var="$banners.1">google-javascript-code</xen:set>
 
<xen:set var="$banners.2">another-adnetwork-javascript-code</xen:set>


Or is only html allowed?

Thanks,

J.
 
Ok, I'll look like an idiot for sure but I can't make it work..

I have put this in my ad_above_content :


<xen:hook name="ad_above_content" />

<xen:comment>DEFINE AND RANDOMIZE YOUR BANNERS</xen:comment>

<xen:set var="$banners.1">http://assettocorsa.fr/img/bandeau1.png</xen:set>
<xen:set var="$banners.2">http://assettocorsa.fr/img/bandeau2.png</xen:set>
<xen:set var="$banners.3">http://assettocorsa.fr/img/bandeau3.png</xen:set>
<xen:set var="$banners.3">http://assettocorsa.fr/img/bandeau4.png</xen:set>


{xen:raw '$banners.{xen:calc '({$serverTime} % 4) + 1'}'}

I know nothing about coding so I should probably stay away from this kind of modifications ... but I love my banners :D

Thanks for any advice.

Fred
Happy Xenforo customer !
 
Ok, I'll look like an idiot for sure but I can't make it work..

I have put this in my ad_above_content :




I know nothing about coding so I should probably stay away from this kind of modifications ... but I love my banners :D

Thanks for any advice.

Fred
Happy Xenforo customer !

You are defining $banners.3 twice. You probably mean for the last one to be $banners.4

You probably also want to enclose the image URLs in a HTML img tag so they display on the page:

Code:
<img src="{xen:raw '$banners.{xen:calc '({$serverTime} % 4) + 1'}'}" />
 
Ok Jake I understand better now !

But I think I miss read something cause I thought it was the upper banner changing... but it show just above my forum :D

Is it some other template I need to work on ?

Thanks for your help !!

error.webp


Fred
 
I'm having a problem with this code. I can see my banners fine from 2 different locations, but everyone else doesnt see them. When i change to static banner code. Everyone can see it. Any idea what's happening?
 
Yes. I even went as far to use CCleaner and completely wipe the cache and i tried in a different browser and i could see it fine. But everyone else saw a missing image.
 
I put the static image code back and all my users were able to view it. They were using Chrome and Opera. I tested in Firefox and IE. I did notice something odd in the page source, there were 5 blank lines at the top between the <a href=""> and the </a> tags. Maybe those browsers dont like this. Also, i haven't changed any code aside from path to image and url link.
 
Hi Jake,

greetings from germany and thanks for this code :)

A question please.......
Is it possible to make that every banner is a link to another website?
So i have more than ten dealers and i randomize their logos.
Now they wish to have a linked logo to their website.

Maybe possible?
 
Thanks for this guide @Jake Bunce :)

Is it possible to make that every banner is a link to another website?


@bt012ss, sure, you can. For instance, this is what I have:

HTML:
<xen:set var="$banners.1">
<a href="http://www.example.com"><img src="/path/to/image1.gif"></a>
</xen:set>
<xen:set var="$banners.2">
<a href="http://www.example.net"><img src="/path/to/image2.gif"></a>
</xen:set>

Hope it helps. :)
 
Thank you once again :)

But i still have a problem.
My code and the results :confused:

Code:
<xen:set var="$banners.1">
<a href="http://www.path.de"><img src="http://www.path.de/images/header/header1.jpg"></a></xen:set>

random4.webp

Code:
<xen:set var="$banners.1"><a href="http://www.path.de"><img src="/images/header/header1.jpg"></a></xen:set>

random5.webp

An idea where my thought is incorrect?
 
Top Bottom