Randomizing Web Content

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

  1. ghall macrumors 68040


    Jun 27, 2006
    Rhode Island
    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

    Mar 4, 2005
    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

    Jun 21, 2007
    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:

    <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" />
    <img src="ad4.jpg" />
    I lost my code for doing this in PHP. Sorry. :(

Share This Page