• I’m working on a theme where I want to add specific classes to the wrapper around each widget, depending on whether it is the first widget in the sidebar, second, third, etc. The reason I’m doing this is to get the widgets laid out using the Blueprint CSS framework.

    For the time being, I’m handling this by creating a customized version of the dynamic_sidebar function and sticking that in my theme’s “functions.php”. This approach works, but is obviously brittle, and other theme developers might benefit from being able to customize their widgets’ presentation by position.

    I propose passing the count of the current widget to the theme, and allowing for values returned by functions to be included in the register_sidebar(array(whatever)) Perhaps this is already possible and I’m missing it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Look closer at the dynamic_sidebar_params filter. You can edit the widget parameters that way, allowing you to include classes and id’s and such.

    Thread Starter adamrice

    (@adamrice)

    I have indeed been looking at that. However:

    A) Can I get the count of the current widget? It doesn’t seem like it. I needed to modify the line
    foreach ( $sidebars_widgets[$index] as $id )
    to
    foreach ( $sidebars_widgets[$index] as $CountOfThisWidget => $id )
    just to get the count within the dynamic_sidebar function.

    B) Can I inject a value returned by a function into dynamic_sidebar_params? If so, I’d appreciate an example of the syntax.

    thanks.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Can I get the count of the current widget?

    … Can you not keep your own count?
    function whatever() {
    global $my_count;
    $my_count++;

    Can I inject a value returned by a function into dynamic_sidebar_params? If so, I’d appreciate an example of the syntax.

    I’m not entirely certain what you mean here… It’s a filter. Do you know how to use those?
    http://codex.wordpress.org/Plugin_API#Filters

    Thread Starter adamrice

    (@adamrice)

    Thanks. Filters are new to me, but I can see how they’d do what I need. And yes, now that you mention it, I can use a global to keep my own count.

    thanks again.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Callback to themes for dynamic sidebar function’ is closed to new replies.