WordPress.org

Ready to get started?Download WordPress

Forums

Callback to themes for dynamic sidebar function (5 posts)

  1. adamrice
    Member
    Posted 6 years ago #

    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.

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  3. adamrice
    Member
    Posted 6 years ago #

    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.

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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

  5. adamrice
    Member
    Posted 6 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic