Created
May 2, 2012 12:07
-
-
Save markoheijnen/2576124 to your computer and use it in GitHub Desktop.
Class to enable a nice way to let the user have a horizontal sidebar
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 | |
class Sidebar_Horizontal { | |
public $end_row = '<div class="clearfix"></div>'; | |
private $registered = array(); | |
private $counter = array(); | |
function __construct() { | |
add_filter( 'dynamic_sidebar_params', array( &$this, '_sidebar_params' ) ); | |
} | |
function register( $sidebar_id, $columns ) { | |
$this->registered[ $sidebar_id ] = intval( $columns ); | |
} | |
function _sidebar_params( $params ) { | |
$sidebar_id = $params[0]['id']; | |
if( ! isset( $this->registered[ $sidebar_id ] ) ) { | |
return $params; | |
} | |
if( ! isset( $this->counter[ $sidebar_id ] ) ) { | |
$this->counter[ $sidebar_id ] = 0; | |
} | |
$this->counter[ $sidebar_id ]++; | |
if( $this->counter[ $sidebar_id ] % $this->registered[ $sidebar_id ] == 0 ) { | |
$params[0]['before_widget'] = preg_replace( '/class="/', "class=\"last ", $params[0]['before_widget'], 1 ); | |
$params[0]['after_widget'] = $params[0]['after_widget'] . $this->end_row; | |
} | |
return $params; | |
} | |
} | |
$sidebar_horizonal = new Sidebar_Horizontal(); | |
$sidebar_horizonal->register( 'footerbar', 4 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment