Dynamic width depending on sidebars in wordpress

im building wordpress theme and i created 4 sidebars to use on footer, now i need to have dynamic width of those 4 sidebars depending of how many of them are active.

So for example if i have only footer1 sidebar active, his width should be 100%

If i have footer1 and footer2, or footer1 and footer4, or footer2 and footer3 active they should be 50%,

If i have 3 of them active 33%

And if i have all 4 of them each one should be 25% width.

Just to say again, these are not active widgets in one sidebar, all 4 of them are separated sidebars.

I think this could be done with "switch" and "case" php functions, or with "if" but i don't know how to count them.


It looks like you could use wp_get_sidebars_widgets, which returns an associative array of sidebars and their widgets.

With that in mind you could do something like this to set the width of the sidebar. You will need to create the CSS classes to match the names I've chosen to specify the width.

$sidebars = wp_get_sidebars_widgets();
$count = count($sidebars['sidebar-area-name']);
$class_name = 'widget_count-' . $count;

// an alternative to a class would be
// $width = round(100 / $count);

Need Your Help

Access object of to-many relationship

objective-c parse.com

I have an object with a to-many relationship. It goes Workout<-->>Workout Score. If I have the workout score, how can I access the workout? I am using Parse.com.

Problems with Dispatcher.Invoke and thread access

c# .net visual-studio multithreading thread-safety

I've trying to handle threads in C#, but i've occurred in a wierd exception I don't know how to resolve. I've got a method running by BackgroundWorker, in which there's this piece of code:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.