Randomizing Web Content

Discussion in 'Web Design and Development' started by ghall, Jul 8, 2007.

  1. ghall macrumors 68040

    ghall

    Joined:
    Jun 27, 2006
    Location:
    Rhode Island
    #1
    Hi. I was wondering if there was some code to rotate web content, such as ads. If so, where can I get it?
     
  2. 2Sticky macrumors regular

    Joined:
    Mar 4, 2005
    Location:
    UK
    #2
    Try google, there is Javascript code to allow you to have an image change after a certain time, or theres one that will display a random images, or ad each time the page is refreshed.

    Depends what you want, just try googling.
     
  3. Mac In School macrumors 65816

    Joined:
    Jun 21, 2007
    #5
    I'm not a fan of using Javascript unless it's absolutely necessary. When possible, I prefer to do these things server-side. Search engines like me better for it. :)

    Here's a way to do this in ColdFusion:

    HTML:
    <cfset pickQ1 = '#randrange(1,4)#' />
    
    <cfif #pickQ1# EQ "1">
    
    <img src="ad1.jpg" />
    
    <cfelseif #pickQ1# EQ "2">
    
    <img src="ad2.jpg" />
    
    <cfelseif #pickQ1# EQ "3">
    
    <img src="ad3.jpg" />
    
    <cfelse>
    
    <img src="ad4.jpg" />
    
    </cfif>
    I lost my code for doing this in PHP. Sorry. :(
     

Share This Page