Article

Build a Rotating Gallery in ColdFusion

Page: 1 2 3 4

The second output will be from the start of the recordset to the end_item value.

 <cfloop query="qGallery" startrow="1" endrow="#end_item#">    
   <cfset col_tick = IncrementValue(col_tick)>    
   <cfset count = IncrementValue(count)>    
   <cfoutput>    
     <td width="40"><img src="#pic_thumb#" height="#pic_y#"    
     width="#pic_x#" alt="#pic_title#"></td>    
       <cfif count EQ total_items>    
         </tr></table>    
       <cfelseif col_tick EQ columns>    
         </tr><tr><cfset col_tick = 0>    
       </cfif>    
   </cfoutput>    
 </cfloop>    
   
</cfif><!--- close if start_item LT end_item --->

Now we close our if statement.

</div>    
   
</body>    
</html>    
</cfprocessingdirective>

Close our page, and we're finished!

Considerations

This code could just as easily be applied to blocks of text or banners. If you'd like it to rotate at an interval other than daily, adjust this line:

<cfset start_day = DateDiff("y","01/01/2000",Now())>

The "y" returns the number of days between 01/01/2000 and the present. To make the gallery rotate on the hour, change the "y" to an "h". See the ColdFusion documentation for a complete discussion of the DateDiff function.

The contents of our loops are all very similar, if we leave in the if statements we omitted during the second sets of output, we could put this code into an include file.

Add some more fields to the database, and you could have the thumbnails lead to larger pics, accompanied by descriptive paragraphs.

With some modification, this can become a great custom tag! I've used it to rotate on sale items for other sites. Feel free to modify the code, let me know what you come up with!

Conclusion

We've made our client happy, and created a better gallery. The visitor's thrill of having their picture on the Website is only augmented by the fact that it will be there for a set time, disappear for a spell, and then return later. If you had just spent one year and two gazillion bucks building a space-tube chassis 1923 T-Bucket with a screaming powerplant and Weber stacks, wouldn't you want to show your friends the site you posted it to? The customers are now performing targeted marketing for the site owners!

Now go forth and multiply--or rather, divide and conquer.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links

Rate This Article

  • 1
    Poor
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
    Great

Post A Comment

You need to be a member of the SitePoint Forums to comment on this post. Sign Up

Already a member? Post using your SitePoint Forums account: