WordPress.org

Ready to get started?Download WordPress

Ideas

Extra Argument in before_widget to determine its position in the sidebar

  1. fr33think3r
    Member

    It would be helpful to have a extra argument in before_widget

    wp-includes/widgets.php
    $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_, $widgetnth);

    where $widgetnth is the position of the widget in the sidebar, i.e. whether its the first widget, second widget etc. This can be used in generating class definitions using which a theme developer can write widget independent, position dependent css.

    For Eg.
    'before_widget' => '<div id="%1$s" class="widget %2$s widget-%2$s widget%3$s"><div class="widget-inside">'

    here widget%3s will generate class names like widget1, widget2 etc.

    This can be useful in various scenarios. One use case is

    2 widgets are stacked horizontally, and I want to set the width of the left widget as x and that of the right widget as y. There's no way to accomplish that without using hardcoded widget classes in the css.

    Posted: 3 years ago #
  2. fr33think3r
    Member

    The code here looks gibberish. I have blogged about this here with code and more details.

    Posted: 3 years ago #
  3. Andy Macaulay-Brook
    Member

    12345

    I could do with something like this myself, although it's usually the list elements in nav menus I want to count.

    However my feeling is that we should really be using css3 to style the nth elements in lists and perhaps using one of the available js libraries to extend such capabilities to IE.

    You could also look at hooking into the dynamic_sidebar_params filter to add your own counts into the classes. Look at /wp-includes/widgets.php for the source code of the dynamic_sidebar() function which calls this hook.

    Posted: 3 years ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    11 Votes
  • Status

    This idea is under consideration