Support » Themes and Templates » Widgets and alternating styles

  • Hello,

    I’m trying to “widgetize” my current theme and I’m running into a bit of a problem. What I’d like to do is have alternating styles applied to each widget in the sidebar. In my case, this would be alternating colors. In my old static sidebar, I simply had a counter that I took the remainder of when dividing by two. I can’t do that with widgets.

    Does anybody know of a theme that does this already so I can take a look or know of a way to accomplish that.



Viewing 3 replies - 1 through 3 (of 3 total)
  • Bump…

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    That is a tricky one, isn’t it?

    You could do it by modifying the widgets.php file itself. You’ll want to modify the dynamic_sidebar function.

    In there is a foreach loop. It contains a sprintf function call. This sprintf is creating the list item for each widget. The last parameter of this sprintf is the contents of the class for that li.

    What you want to do is to add a counter or something like that in here. When the loop counter is odd, you append ” widgetodd” to that last parameter of the sprintf, when it’s even, you append ” widgeteven” to it. This will add alternating classes for your widgets going down the page, and then you can style the odds and evens separately in your CSS file.

    Interesting notion, I like it.

    Thanks! I’ll give it a look.



Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Widgets and alternating styles’ is closed to new replies.