• Resolved tbag

    (@tbag)


    Question: How do i integrate PHP into my CSS?
    Why: I want to have a random header image, and the 2 plugins i grabbed won’t work.
    ———————————————–
    So far:
    in my style.css i want to edit this entry:
    ———————————————–
    #headerimg {
    background: url(“images/header.jpg”);
    }
    ———————————————–
    And i have this php to grab random images (named 1.jpg, 2.jpg) from a folder.
    ———————————————–
    <?php

    // Change this to the total number of images in the folder
    $total = “2”;

    // Change to the type of files to use eg. .jpg or .gif
    $file_type = “.jpg”;

    //Starting the randomizing

    $start = “1”;

    $random = mt_rand($start, $total);

    $image_name = $random . $file_type;

    echo $image_name;

    ?>
    ———————————————–
    The images and the php will be in the same folder.

    So how do i integrate my PHP file into my CSS? Just naming it in the url tag won’t work.

    any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • make a php function that will generate the css style header , you pass the info to the function and function will generate the stylle depending of what it get ..


    function php_generate_css ($image_name , $more_if_needed) {

    echo " <style>
    background: url(\"images/$image_name.jpg\");
    </style>
    ";

    }

    and when u want to call : php_generate_css ("1.jpg","more variables if needed") ;

    Thread Starter tbag

    (@tbag)

    beauty thats clever. ty.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to call PHP in your CSS: specifically changing header imgs’ is closed to new replies.