0

is there any Way to Catch Last widget box or div from same widget area?? i mean i have 4 widgets in footer widget area but due to design issue my 3rd widget box style+width is different.so i want to add extra class to 3rd box container using php.is there any way to do that? please reply.

Thanks in advance. :)

0

Add the following code in your functions.php file of the theme directory. Replace widget name "Home Widget Area" with your widget's name

    /*=============WIDGETs CSS CLASS CONTROLLER==============*/
    $GLOBALS['my_widget_num']=1;
    function edei_widget_class_adder($params){
    if( $params[0]['name']=='Home Widget Area' ){
        $GLOBALS['my_widget_num']++;
        if( ($GLOBALS['my_widget_num']%4)==0 ){
            $params[0]['before_widget'] = str_replace('class="', 'class="marginAdjust ', $params[0]['before_widget']);
        }
    }

    //print_r($params);
    return $params;
}
add_filter('dynamic_sidebar_params','edei_widget_class_adder');

function edei_widget_counter_reset($sidebars_widgets) {
   $GLOBALS['my_widget_num'] = 1;
   return $sidebars_widgets;
}
add_filter('sidebars_widgets','edei_widget_counter_reset');
  • This wont work as there's a bracket too much. – kaiser Oct 9 '12 at 12:21
1

Usually in Worpdress every widget has a unique id of the form "widget_type-xx" where widget_type is the widget internal name, and xx is a progressive number. I think you may use that id to apply custom css rules, and you don't really need to add a class via php, unless that widget will be replaced in future (the id would change in that case).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.