Created
July 19, 2012 01:46
-
-
Save BronsonQuick/3140250 to your computer and use it in GitHub Desktop.
Count the number of widgets in a sidebar in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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