SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Random Background in pages

    I have been looking all over the internet for an answer to my question. Have come close in finding it but to no avail.

    Here is what I want to do. I have a site with over 300 videos, with each one having its own html to play in an embedded player. I use css to format the pages for a table around the player, and formatting of the text on the pages. I would like to have a way for it to apply different backgrounds when someone plays a video. So basically with 300+ pages linked back to one css and with 7 background images available to those 300+ pages, how can i have the one css change the background randomly when a video page is opened? I want to do this so I don't have to edit 300+ pages LOL. I use Arles to generate the pages and the css file by the way. So I only want to edit the one css file. Also, I don't want a header, border, or table image, just a plain background tiled. PHP and CSS code will be most welcomed!! Thanks in advance for anyones assistance.

    p.s. help with what to do with the code would be most appreciated also hehe... very new to css and totally new to php
    Last edited by bobfrantic; Dec 10, 2008 at 08:01.

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could turn your stylesheet into a php file so instead of style.css it would be style.php. Then inside your style.php at the top put:
    PHP Code:
    <?php
    header
    ("Content-type: text/css");
    $bg=rand(1,7);
    ?>
    Name your background images and save them in your images folder or where ever you have them like so:
    background1.jpg
    background2.jpg
    background3.jpg
    background4.jpg
    background5.jpg
    background6.jpg
    background7.jpg

    Now in your styles where you set the background:
    Code:
    body{background:url(background<?=$bg?>.jpg);}
    This should do it but you're still going to have to edit all 300 pages to change style.css to style.php.. I can think of a lot of ways to do it but none that allow you to do it without editing the pages somehow.

  3. #3
    SitePoint Member
    Join Date
    Dec 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Appreciate your response Brad, I have seen this one on the web before... What I would like is to use a rotate php type script that is captured by code in my image css if possible... Will keep looking though, optimistically stubborn. haha

    I have found a way to put the link to the php file in the header of the video pages, so went ahead and tried your suggestion. when I checked the php i got the following error refering to: <?phpheader("Content-type: text/css");$bg=rand(1,7);?>

    Fatal error: Call to undefined function phpheader() in C:\Users\John\Desktop\random\image.php on line 1

    i named the pictures as you suggested, and are in a folder named images.

    my file has:

    <?phpheader("Content-type: text/css");$bg=rand(1,7);?>


    body {
    background:url(images<?=$bg?>.jpg);
    color : #000000;
    font-family : Tahoma, Arial, sans-serif;
    font-size : small;
    margin-top: 03&#37;
    }

    with the <?=$bg?> in red.

    any ideas? please??

    thanks
    Last edited by bobfrantic; Dec 10, 2008 at 23:36.
    Everything I tell you is a lie, including this

  4. #4
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd have the PHP generate a random class on the body element, and then just reference each class (and its associated image) in the stylesheet. That way the CSS file gets cached and the individual page can pull up the random image by switching between classes.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •