Resource icon

Display A Random Banner

I wonder if there is any specific way to properly insert code snippets, like Google AdSense ones, in between of each <xen> tags.

I mean, it looks like this snippet is not working properly. The banner is not showing up at all and also the forum layout is being affected somehow:

<xen:set var="$banners.1">
<!-- Code -->
<div id='div-gpt-ad-3487417992475-2' style='width:160px; height:600px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-3487417992475-2'); });
</script>
</div>
</xen:set>

Any ideas?

Thanks! :)
 
I wonder if there is any specific way to properly insert code snippets, like Google AdSense ones, in between of each <xen> tags.

I mean, it looks like this snippet is not working properly. The banner is not showing up at all and also the forum layout is being affected somehow:

<xen:set var="$banners.1">
<!-- Code -->
<div id='div-gpt-ad-3487417992475-2' style='width:160px; height:600px;'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-3487417992475-2'); });
</script>
</div>
</xen:set>

Any ideas?

Thanks! :)

Check the source code of the page. I suspect the code is present (meaning the randomization code is working). Though the javascript code you are using may not be working.
 
Jake Bunce
Hello.
Tell, please, at me on the page is shown on 5 banners directly how to make that they were interchanged the position in case of each reload by the browser?

Thanks.
 
Hello,

it is posible to display eg 3 random banners out from a pool of X Banners in a spezified directory on my server AND refresh these 3 banners after X (10 eg, or 15) seconds without page refresh?

I have such a solution in my forum ( www.hobby-gartenteich.de ) but its not so smart coded (2 external php files, iframe, js ... :( ) so I search for a cleaner, better solution like yours, but with the above settings.

Thanks for every constructive answers. :)
 
Thanks for this modification.:)

I have a questions. How to write all the banners with random order (example in sidebar)?
 
How to write all the banners with random order (example in sidebar)?
I don't understand your question.

You can use one of the ad_sidebar_* templates to add the code. For example, for a total of three banners:

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

<xen:set var="$banners.1">banner one</xen:set>
<xen:set var="$banners.2">banner two</xen:set>
<xen:set var="$banners.3">banner three</xen:set>

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

Even though that is an ordered list ($banners.1, $banners.2, etc), the banners themselves will be displayed in a random way.
 
I don't understand your question.

You can use one of the ad_sidebar_* templates to add the code. For example, for a total of three banners:

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

<xen:set var="$banners.1">banner one</xen:set>
<xen:set var="$banners.2">banner two</xen:set>
<xen:set var="$banners.3">banner three</xen:set>

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

Even though that is an ordered list ($banners.1, $banners.2, etc), the banners themselves will be displayed in a random way.

I am sorry for my english. I need to insert page banners ALL I've got (no only one of them), every time the page is loaded in a different order. For example:

First time:
A-banner
C-banner
B-banner

Second time:
C-banner
B-banner
A-banner

Third time:
B-banner
C-banner
A-banner...
 
I am sorry for my english. I need to insert page banners ALL I've got (no only one of them), every time the page is loaded in a different order. For example:

First time:
A-banner
C-banner
B-banner

Second time:
C-banner
B-banner
A-banner

Third time:
B-banner
C-banner
A-banner...

Hmm. This guide shows how to select a banner at random, not display all banners on one page in a random order.

One possibility would be to use a loop over the length of the array with a modulo index starting at a random point, but that would only ensure a random starting point after which it would display in order from that point (abc, bca, cab). Better randomization would require a heavier algorithm.
 
One possibility would be to use a loop over the length of the array with a modulo index starting at a random point, but that would only ensure a random starting point after which it would display in order from that point (abc, bca, cab). Better randomization would require a heavier algorithm.

I understand, what do you mean, but i dont know, how it do it in template. I thought this would be possible by editing this guide.
In php i can use array_rand(). Is anywhere tutorial for this use? Im sorry Im off topic, please move my questions (?)
 
I understand, what do you mean, but i dont know, how it do it in template. I thought this would be possible by editing this guide.
In php i can use array_rand(). Is anywhere tutorial for this use? Im sorry Im off topic, please move my questions (?)

That function is not available to the templates. Yes, you can do it in PHP but that requires a proper addon.
 
Code:
<xen:comment>DEFINE AND RANDOMIZE YOUR BANNERS</xen:comment>

<xen:set var="$banners.1">banner one</xen:set>
<xen:set var="$banners.2">banner two</xen:set>
<xen:set var="$banners.3">banner three</xen:set>

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

Hi i use this to show banners in the header side the logo (ad_header) and works ok, without problems.

But in the mobile version break the design so i need to know how to not show to the mobile version the banners, there is any conditional that can be implemented?
 
Ok, i have done it. I will share my configuration to other ppl, this configuration is to rotate random banners side by side the logo in the top.

Add this to to template EXTRA.css

Code:
@media (max-width:640px){
    .myBanners {
       display: none;
    }
}


Add this to the template ad_header
Code:
<div class="myBanners">
<div style="float: right; margin: 15px 130px 0px 0px;">
<xen:comment>Banners Random Top</xen:comment>

<xen:set var="$banners.1"><a href="http://www.xenforo.com" target="blank" rel="nofollow"><img src="http://www.myurlforum.com/banner1.gif" alt="Company name 1"></a></xen:set>
<xen:set var="$banners.2"><a href="http://www.xenforo.com" target="blank" rel="nofollow"><img src="http://www.myurlforum.com/banner2.gif" alt="Company name 2"></a></xen:set>
<xen:set var="$banners.3"><a href="http://www.xenforo.com" target="blank" rel="nofollow"><img src="http://www.myurlforuml.com/banner3.gif" alt="Company name 3"></a></xen:set>

{xen:raw '$banners.{xen:calc '({$serverTime} % 3) + 1'}'}</div>
</div>


Some considerations:
I use banners size 460px × 60px so if you use another size maybe you need to change the values in margin: 15px 130px 0px 0px.
alt tag to identify the name the company.
rel="nofollow" to benefit SEO.
target="blank" to open the link in other tab.
 
Last edited:
I would love to see this for 2.1 as well, great script for A/B testing as well as simple banner rotation.
 
Top Bottom