Skip to content

Instantly share code, notes, and snippets.

@markoheijnen
Created May 2, 2012 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markoheijnen/2576124 to your computer and use it in GitHub Desktop.
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
<?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