Random CSS background Images

Author Message

Martin Sanders

Friday 07 April 2006 2:25:02 pm

Hi I've been working on placing a random image in the background of a div, but have found that for some reason the permissions of our eZ publish website server account will not allow our PHP script to select random images. I've found that this issue is related to ez, does anyone know how we can implement such an effect within our ez website.

http://www.alistapart.com/articles/randomizer

Kind regards,

Gabriel Ambuehl

Saturday 08 April 2006 6:29:17 am

You will likely have to put the php script that sends the images to the browser in a directory that is not being covered by mod_rewrite I guess. The specific location depends a lot on your actual mod_rewrite config.

Or write an extension to send out the images...

Visit http://triligon.org

André R.

Saturday 08 April 2006 6:30:03 am

I think they have added a randomizer function in v3.8.
With that you could set different css classes on the body tag, and use css to have different styles / backgrounds based on that class.

body.style1 div#mydiv {bacground: #fff url(my_img.gif) left top no-repeat scroll;}
body.style2 div#mydiv {bacground: #fff url(not_my_img.gif) left top no-repeat scroll;}

In earlier versions you could use time stamps as the randomizer, for instance seconds. You could have 60 different styles That would seem quite random to the surfer as well..

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Mark Marsiglio

Saturday 08 April 2006 8:28:00 am

We did this by using the shuffle contribution and calling images from a special folder in the Media Section.

We set the shuffle operator on a fetch that called images from that folder (by parent node) using a limit of 1. Then the fetch is embedded in an inline style - background-image for that div.

I don't have the code handy, but can post it if you need it.

http://www.thinkcreative.com
Turning Ideas Into Strategic Solutions

Betsy Gamrat

Saturday 08 April 2006 10:32:07 am

Thanks!

I didn't know about <b>shuffle</b> and I need it for the project I'm working on. You just saved me alot of time.

:)

David Jones

Thursday 31 August 2006 9:34:32 am

Mark,

I realize that this was posted some time ago but do you still have that code floating around?

I need to do something similar

Thanks

Claudia Kosny

Thursday 31 August 2006 10:55:23 am

Hello David

The post by Marc Boon in this thread
http://ez.no/community/forum/setup_design/how_to_fetch_random_content_3_8/re_how_to_fetch_random_content_3_8__3
gives a nice solution on how to fetch a single random object (and some ideas on how to fetch more than one)
Limit the fetch to your pictures, grab the path to the picture and add it to your style information.

Greetings from Luxembourg

Claudia

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 08:17:45
Script start
Timing: Jan 31 2025 08:17:45
Module start 'layout'
Timing: Jan 31 2025 08:17:45
Module start 'content'
Timing: Jan 31 2025 08:17:45
Module end 'content'
Timing: Jan 31 2025 08:17:45
Script end

Main resources:

Total runtime0.0132 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0045 588.1328151.2109
Module start 'layout' 0.00460.0021 739.343836.6484
Module start 'content' 0.00670.0053 775.992298.2656
Module end 'content' 0.01200.0012 874.257837.9922
Script end 0.0132  912.2500 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002116.2274140.0002
Check MTime0.00107.6994140.0001
Mysql Total
Database connection0.00075.200910.0007
Mysqli_queries0.002115.611830.0007
Looping result0.00000.068610.0000
Template Total0.00096.810.0009
Template load0.00075.193710.0007
Template processing0.00021.590410.0002
Override
Cache load0.00053.572610.0005
General
dbfile0.001712.690980.0002
String conversion0.00000.045140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs