• Hello.

    I am calling wp_list_categories within a pair of UL tags and this is creating me a nice list of categories.

    Now I want to be able to have a different background colour for each item (li).

    If I were to manually create the list I could do something like the following:

    <ul>
     <li class="red"><a href="cat1Link">Cat 1</a></li>
     <li class="blue"><a href="cat2Link">Cat 2</a></li>
     <li class="green"><a href="cat3Link">Cat 3</a></li>
    </ul>

    and then set up my CSS to alter the background colour based on the li class.

    When using wp_list_categories the li comes out like:
    <li class="cat-item cat-item-33">
    So I could set the CSS to alter the colours based on the cat-item-xx codes but that seems wrong to me as the CSS would not be nice and generic and would require changing each time it was used.

    What would be good is if there was a more dynamic method. Something like a CSS that changes each use, so first use it specifies the colour would be red, the second blue, the third green and then cycle back around.

    Any idea if that is possible or if there is another way of achieving this effect.

    Cheers.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think use some JQ functions maybe helpful.
    Just choose the right
    <li> and give them different colors style="color:#".

    Thread Starter nhiggs

    (@nhiggs)

    Could you explain that further please? I don’t know JQ yet.
    The main issue is selecting an li without directly specifying the classes ‘cat-item-xx’. Setting the colour is the easy bit.
    Ta

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_list_categories with each item having a different colour’ is closed to new replies.