• Resolved avecchioni

    (@avecchioni)


    wp 2.84/ theme: sliding doors

    I’m having trouble using php in a css (image menu) file. I’d like to change this:

    #imageMenu ul li.bk1 a {
    	background: url(images/A_1.jpg) repeat scroll 0%;
    }

    to this:

    #imageMenu ul li.bk1 a {
    	background: url(images/A_<?php echo(rand(1,7)); ?>.jpg) repeat scroll 0%;
    }

    The images A_1 thru A_7 have been uploaded via ftp to the appropriate folder, but the code produces white space where the random photo should appear. I’ve used the echo code in ordinary theme files previously, but don’t know how to employ it in a css file. Can someone point me in the right direction? Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • php does not get executed in linked external stylesheets.

    I’ve never tried it, but the following should work:

    (1) remove from CSS
    (2) add the following to header.php after the link to CSS (assuming that you are using header.php):

    <style>
    <!--
    #imageMenu ul li.bk1 a {
    	background: url(images/A_<?php echo(rand(1,7)); ?>.jpg) repeat scroll 0%;
    }
    -->
    </style>

    Thread Starter avecchioni

    (@avecchioni)

    Thanks for the reply. Doesn’t seem to be working. I removed from css (image menu) file and inserted into header.php. I even took out the php echo portion of the image url to simplify. The code is now:

    <style>
    <!--
    #imageMenu ul li.bk1 a {
    	background: url(images/A_1.jpg) repeat scroll 0%;
    }
    -->
    </style>

    I tried to insert this (after link to css) in the following locations: Within head tag /After head tag before body tag/ Within body tag/ Within body tag also within div id=”imageMenu”/ And various other places. Any idea what I’m doing wrong? Here’s url: http://mrsvecchionisartroom.com/blog/

    Thread Starter avecchioni

    (@avecchioni)

    If this helps– I also uncommented the code to no avail.

    Thread Starter avecchioni

    (@avecchioni)

    Got it. Per this post: http://www.barelyfitz.com/projects/csscolor/ I made following changes:

    changed name of imageMenu.css to imageMenu.php
    added this to top of imageMenu.php:
    <?php header(“Content-type: text/css”); ?>
    in header.php, changed the stylesheet references from style.css to style.php
    reinserted php echo code (for rotating images) into imageMenu.php

    Tested in firefox and ie, works fine. Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘CSS Help’ is closed to new replies.