开发者

Wordpress sidebar classes

There any way i could add a class for the specific order of widget item? i.e. the class name would be widgetorder-1 (for the first appearing widget), widget开发者_运维知识库order-2 (for the widget appearing in the 2nd order), etc. I looked into filters but wasn't sure how that worked.


// Set this to whatever number you'd like the ordering to start on.
$my_blog_widget_count = 0;
// put your blog sidebar here
$my_blog_sidebar_id = '';

function output_my_widget_info($a){
    global $my_blog_sidebar_id, $my_blog_widget_count;
    if($a[0]['id'] == $my_blog_sidebar_id){
        global $my_blog_sidebar_id, $my_blog_widget_count;
        $a[0]['before_widget'] = preg_replace( '/ class="widget /i', ' class="widget widget-'.$my_blog_widget_count.' ', $a[0]['before_widget'] );
        $my_blog_widget_count++;
    }
    return $a;
}

add_filter('dynamic_sidebar_params','output_my_widget_info');

That should do it for you. Just stick that inside your theme's functions.php file and watch it work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜