How To Implement A Simple Random Banner

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jake Bunce
    Senior Member
    • Dec 2000
    • 46598
    • 3.6.x

    How To Implement A Simple Random Banner

    There are many ways to do this. Here is a simple method that uses PHP's rand() function to randomize the banners.

    Enable Your Plugin System
    You need to use a plugin for this, so first make sure your plugin system is enabled:

    Admin CP -> vBulletin Options -> Plugin/Hook System -> Enable Plugin/Hook System

    Create New Plugin
    Now create a new plugin for the parse_templates hook location:

    Admin CP -> Plugin System -> Add New Plugin

    Use this PHP code in the plugin:

    Code:
    $random_number = rand([color=blue]1[/color], [color=blue]5[/color]);
    
    $random_banner[[color=blue]1[/color]] = '<a href="[color=red]http://www.link1.com/[/color]"><img src="[color=red]path/to/banner1.gif[/color]" alt="" border="0" /></a>';
    $random_banner[[color=blue]2[/color]] = '<a href="[color=red]http://www.link2.com/[/color]"><img src="[color=red]path/to/banner2.gif[/color]" alt="" border="0" /></a>';
    $random_banner[[color=blue]3[/color]] = '<a href="[color=red]http://www.link3.com/[/color]"><img src="[color=red]path/to/banner3.gif[/color]" alt="" border="0" /></a>';
    $random_banner[[color=blue]4[/color]] = '<a href="[color=red]http://www.link4.com/[/color]"><img src="[color=red]path/to/banner4.gif[/color]" alt="" border="0" /></a>';
    $random_banner[[color=blue]5[/color]] = '<a href="[color=red]http://www.link5.com/[/color]"><img src="[color=red]path/to/banner5.gif[/color]" alt="" border="0" /></a>';
    The blue numbers represent the range of random numbers to be generated, or the number of banners you have in your rotation. You need to edit the top two numbers appropriately, and then create a $random_banner[X] line for each number in the range. In the above code, the random number is between 1 and 5, inclusive, and there are five banners defined.

    Change the red code appropriately for each banner.

    Display The Banner
    Use this code in any template to display the random banner:

    Code:
    $random_banner[$random_number]
    The header template is a common place to insert banners:

    Admin CP -> Styles & Templates -> Style Manager -> Common Templates (in the menu) -> header

    Replace the red code:

    Code:
    <!-- logo -->
    <a name="top"></a>
    <table border="0" width="$stylevar[outertablewidth]" cellpadding="0" cellspacing="0" align="center">
    <tr>
    	<td align="$stylevar[left]"><a href="$vboptions[forumhome].php$session[sessionurl_q]"><img src="$stylevar[titleimage]" border="0" alt="$vboptions[bbtitle]" /></a></td>
    	<td align="$stylevar[right]">
    		[color=red]&nbsp;[/color]
    	</td>
    </tr>
    </table>
    <!-- /logo -->
    
    <!-- content table -->
    $spacer_open
    
    $_phpinclude_output
    ...with the blue code:

    Code:
    <!-- logo -->
    <a name="top"></a>
    <table border="0" width="$stylevar[outertablewidth]" cellpadding="0" cellspacing="0" align="center">
    <tr>
    	<td align="$stylevar[left]"><a href="$vboptions[forumhome].php$session[sessionurl_q]"><img src="$stylevar[titleimage]" border="0" alt="$vboptions[bbtitle]" /></a></td>
    	<td align="$stylevar[right]">
    		[color=blue]$random_banner[$random_number][/color]
    	</td>
    </tr>
    </table>
    <!-- /logo -->
    
    <!-- content table -->
    $spacer_open
    
    $_phpinclude_output

    Calling Specific Banners
    You can call a specific banner in the templates by using that banner's number. For example:

    Code:
    $random_banner[3]
  • Steve Machol
    Former Customer Support Manager
    • Jul 2000
    • 154488

    #2
    Note: This is not an officially supported modification. If you have questions or need assistance with this, please ask over at www.vbulletin.org.
    Steve Machol, former vBulletin Customer Support Manager (and NOT retired!)
    Change CKEditor Colors to Match Style (for 4.1.4 and above)

    Steve Machol Photography


    Mankind is the only creature smart enough to know its own history, and dumb enough to ignore it.


    Comment

    • jkcerda
      Member
      • Mar 2008
      • 62
      • 3.0.7

      #3
      cool, ill try it

      Comment

      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
      Working...