WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Alternating Sidebar Widget Styles (4 posts)

  1. eryanv
    Member
    Posted 4 years ago #

    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?

  2. alanft
    Member
    Posted 4 years ago #

    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.

  3. eryanv
    Member
    Posted 4 years ago #

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

    Thanks.

  4. jacMadsen
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic