1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Display A Random Banner

Template code to define and randomize banners.

  1. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Jake Bunce submitted a new resource:

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

    Read more about this resource...
     
    japersonal and Mike Creuzer like this.
  2. Mike Creuzer

    Mike Creuzer Well-Known Member

    Awesome, great tutorial. Could you tell me what the conditional is for just the homepage?
     
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Code:
    <xen:if is="{$contentTemplate} == 'forum_list'">
    
    </xen:if>
    
     
    AntonioC likes this.
  4. MsJacquiiC

    MsJacquiiC Well-Known Member

    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.
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Yes.
     
  6. MsJacquiiC

    MsJacquiiC Well-Known Member

    Thanks!
     
  7. Fredjo

    Fredjo Active Member

    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 !
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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'}'}" />
    
     
  9. Fredjo

    Fredjo Active Member

    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.jpg


    Fred
     
  10. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  11. |Jordan|

    |Jordan| Active Member

    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?
     
  12. Fredjo

    Fredjo Active Member

    Might sound stupid from a n00b like me but did you try to empty your cache ?
     
  13. |Jordan|

    |Jordan| Active Member

    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.
     
  14. Fredjo

    Fredjo Active Member

    mmm then I think you'll need someone way better than me ;)

    Might come in handy to post the code you changed here though
     
    Jake Bunce likes this.
  15. |Jordan|

    |Jordan| Active Member

    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.
     
  16. bt012ss

    bt012ss Well-Known Member

    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?
     
  17. japersonal

    japersonal Member

    Thanks for this guide @Jake Bunce :)


    @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. :)
     
    bt012ss and Jake Bunce like this.
  18. bt012ss

    bt012ss Well-Known Member

    Of course @japersonal

    thank you very much :)

    I will try it later.
     
    Last edited: Dec 10, 2013
  19. japersonal

    japersonal Member

    You're welcome :)
     
  20. bt012ss

    bt012ss Well-Known Member

    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.jpg

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

    An idea where my thought is incorrect?
     

Share This Page