Skip to content

Instantly share code, notes, and snippets.

@artboard-studio
Created December 21, 2013 11:07
Show Gist options
  • Save artboard-studio/06fca4141b40fc221fef to your computer and use it in GitHub Desktop.
Save artboard-studio/06fca4141b40fc221fef to your computer and use it in GitHub Desktop.
Sidebar Column Counter
<?php
/**
* Count the number of widgets in a sidebar
* Works for up to ten widgets
* Usage <?php ctm_sidebar_class( 'promo' ); ?> where promo is the name of the sidebar
*/
function ctm_sidebar_class( $sidebar_name ) {
global $sidebars_widgets;
$count = count ($sidebars_widgets[$sidebar_name]);
switch ( $count ) {
case '1':
$class = 'one';
break;
case '2':
$class = 'two';
break;
case '3':
$class = 'three';
break;
case '4':
$class = 'four';
break;
case '5':
$class = 'five';
break;
case '6':
$class = 'six';
break;
case '7':
$class = 'seven';
break;
case '8':
$class = 'eight';
break;
case '9':
$class = 'nine';
break;
case '10':
$class = 'ten';
break;
default:
$class = '';
break;
}
if ( $class )
echo 'class="' . $class . '"';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment