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"):
- Widget is passed through
dynamic_sidebar_params
hook.
- Widget data is
$params[0]
.
- Sidebar name is
$params[0]['name']
.
- 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.