Adding algorithmic class attribute to widget box (3 posts)

  1. adamrice
    Posted 7 years ago #

    I'm working on a theme that has widgets running horizontally across the footer. The theme is styled to have three across.

    It would be helpful if I could hack something to put a different class in the first, second, and third widget-wrapping divs. This would allow me to roll back to the beginning if there's a 4th (or 7th, etc) widget. I'm guessing somewhere I'd need code along the lines of

    switch $countOfThisWidget mod 3 {
    case 1:
    echo "<div class='firstwidget'>";
    case 2:
    echo "<div class='secondwidget'>";
    case 0:
    echo "<div class='lastwidget'>";

    Clearly I'd need to hack an existing function; I'd like to do this in a portable way so that I can distribute the theme and not need to worry about hacking on future copies of WP.

    If we lived in the magical future of CSS3, I wouldn't need to bother with this at all.

  2. adamrice
    Posted 7 years ago #


  3. adamrice
    Posted 7 years ago #

    Got this working by creating a customized version of the "dynamic_sidebar" function and sticking that in my theme's functions.php.

Topic Closed

This topic has been closed to new replies.

About this Topic