Results 1 to 3 of 3

Thread: CSS question, changing TD tag background when category activ

  1. #1
    Thread Starter
    groan's Avatar
    Join Date
    Nov 2009
    Location
    Ottawa, Canada
    Posts
    241
    Thanks
    0
    Thanked 3 Times in 2 Posts

    CSS question, changing TD tag background when category activ

    OK heres a good one for you WP / PHP /CSS gurus.
    Im trying to set the active category to change backgrounds on this page
    http://www.rexandfritz.com"
    You will see a selection of images in <TD>'s along with the category description.
    Here is how one image looks in code.

    Code:
    <td>
    			<a href="http://www.rexandfritz.com/category/cats/"><div><h3>Cats</h3></div>
    			</a>
    			<div><?php echo category_description(1); ?></div>
    		</td>
    What I have learned from the Classipress code is that you can make a call to see if a category is selected and tell it through PHP to apply a class if it is so. This is the code it uses for in my case, Category 6
    Code:
    <?php if ( is_category(6) ) { echo " class=\"current-imag\""; } ?>
    The problem I am having is how to implement this.
    I have created a simple CSS entry to set the TD background-color and I have tried to place that line above in several different places but I can't seem to get it to work.
    Here is my
    CSS code
    Code:
    .current-imag td { background-color:#EEEEEE;}
    If you have any clue I would be grateful. It's not a show-stopper but I would love to get this working.
    No the existing background color is not my final choice, so no need to comment on that.

    Cheers

  2. #2
    Thread Starter
    groan's Avatar
    Join Date
    Nov 2009
    Location
    Ottawa, Canada
    Posts
    241
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Re: CSS question, changing TD tag background when category activ

    Some advance here.
    I have put this line
    Code:
    <div <?php if ( is_category('dogs') ) { echo " class=\"current-imag\""; } ?>>
    before the table that builds that set of images. It works, but when I am on Category 'Dogs' it changes the TD background of all the td's to the colour #333333, as it should. Thats what i told it to do.
    Now I need to figure out how to tell it to do it ONLY in the TD that represents the given category....

  3. #3
    Thread Starter
    groan's Avatar
    Join Date
    Nov 2009
    Location
    Ottawa, Canada
    Posts
    241
    Thanks
    0
    Thanked 3 Times in 2 Posts

    fixed: changing TD tag background when category activ

    OK, Change of option but it works.
    I decided to just change the image i am using for category heading which is in an H3 tag inside the TD.

    here's the code.
    Code:
    <td>
    		    <div <?php if ( is_category('dogs') ) { echo " class=\"current-imag\""; } ?>>
    			<a href="http://www.rexandfritz.com/category/dogs/"><div><h3>Dogs</h3></div>
    			
    			<div><?php echo category_description(6); ?></div></a>
    		    </div>		    
    	</td>
    And it works. I just need to pick a new image.
    Oh, here's the CSS for the above style
    Code:
    .current-imag, {}
    .current-imag h3 {background: url(r-and-f/searchbg.jpg);}
    yay!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)