different class (css) for sidebar widgets

I want to add different class (css) in widgets in site sidebar .

For example:

Read More

First widget in Sidebar -> class=sidebar-top1

Second widget in Sidebar -> class=sidebar-top2

third widget in Sidebar -> class=sidebar-top3

i want to add class in <div> tag.

how i can to do?

Related posts

Leave a Reply

2 comments

  1. What a coincidence, I just spent several hours messing with widget classes. I won’t post my resulting code because it does stuff that is more complex and out of context for your question. Here are basics (or maybe “basics”):

    1. Widget is passed through dynamic_sidebar_params hook.
    2. Widget data is $params[0].
    3. Sidebar name is $params[0]['name'].
    4. Opening widget wrapper is $params[0]['before_widget'].

    So you can filter this hook, check for sidebar you want to modify, keep track of widget count (likely with static variable), modify wrapper and return modified widget parameters.

    I am way to sleepy to write out specific code, leave a comment if you still need help with this and I will get back to it tomorrow.