WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Alternating Sidebar Widget Styles

[Resolved] Alternating Sidebar Widget Styles

  • I’d like my sidebar widgets to alternate between two styles, much like you might have two styles for table rows (one for even numbered rows, and one for odd numbered rows). Can this be done with the dynamic sidebars? If so, how?

Viewing 3 replies - 1 through 3 (of 3 total)
  • you CAN do this with my widget logic plugin

    http://wordpress.org/extend/plugins/widget-logic/

    using the widget_content filter capability. and this in your functions.php:

    add_filter(‘widget_content’, ‘make_alternating_widget_styles’);
    function make_alternating_widget_styles($content=”)
    { global $make_alt_ws;
    $make_alt_ws=($make_alt_ws==”style_a”)?”style_b”:”style_a”;
    return preg_replace(‘/(class=”widget )/’, “$1 widget_${make_alt_ws} “, $content);
    }

    so if your widgets are usually class=”widget …” this will add in “widget_style_a”/”widget_style_b” into that class definition.

    I was hoping something would be built into core, but this works too.

    Thanks.

    jacMadsen
    Member

    @jacmadsen

    Having it in the functions.php file is a much better option as it won’t be saved over when the core is updated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Alternating Sidebar Widget Styles’ is closed to new replies.