Get the current layout.
This function generate the layout class base on the current layout.
beans_get_layout_class( string $id )
Return: (bool) Layout class, false if no layout class found.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
$id | string | true | - | The searched layout section ID. |
Source
function beans_get_layout_class( $id ) {
/**
* Filter the arguments used to define the layout grid.
*
* The content number of columns are automatically calculated based on the grid, sidebar primary and
* sidebar secondary columns.
*
* @since 1.0.0
*
* @param array $args {
* An array of arguments.
*
* @type int $grid Total number of columns the grid contains. Default 4.
* @type int $sidebar_primary The number of columns the sidebar primary takes. Default 1.
* @type int $sidebar_secondary The number of columns the sidebar secondary takes. Default 1.
* @type string $breakpoint The UIkit grid breakpoint which may be set to 'small', 'medium' or 'large'. Default 'medium'.
* }
*/
$args = apply_filters( 'beans_layout_grid_settings', array(
'grid' => 4,
'sidebar_primary' => 1,
'sidebar_secondary' => 1,
'breakpoint' => 'medium',
) );
$g = beans_get( 'grid', $args ); // $g stands for grid.
$c = $g; // $c stands for content. Same value as grid by default
$sp = beans_get( 'sidebar_primary', $args ); // $sp stands for sidebar primary.
$ss = beans_get( 'sidebar_secondary', $args ); // $ss stands for 'sidebar secondary.
$prefix = 'uk-width-' . beans_get( 'breakpoint', $args, 'medium' );
$classes = array();
switch ( $layout = beans_get_layout() ) {
case 'c':
$classes['content'] = "$prefix-$c-$g";
break;
default:
$classes['content'] = "$prefix-$c-$g";
}
// Add sidebar primary layouts if the primary widget area is registered.
if ( $has_primary = beans_has_widget_area( 'sidebar_primary' ) ) {
switch ( $layout ) {
case 'c_sp':
$c = $g - $sp;
$classes['content'] = "$prefix-$c-$g";
$classes['sidebar_primary'] = "$prefix-$sp-$g";
break;
case 'sp_c':
$c = $g - $sp;
$classes['content'] = "$prefix-$c-$g uk-push-$sp-$g";
$classes['sidebar_primary'] = "$prefix-$sp-$g uk-pull-$c-$g";
break;
}
}
// Add sidebar secondary layouts if the primary and secondary widget area are registered.
if ( $has_primary && beans_has_widget_area( 'sidebar_secondary' ) ) {
switch ( $layout ) {
case 'c_ss':
$c = $g - $sp;
$classes['content'] = "$prefix-$c-$g";
$classes['sidebar_secondary'] = "$prefix-$sp-$g";
break;
case 'c_sp_ss':
$c = $g - ( $sp + $ss );
$classes['content'] = "$prefix-$c-$g";
$classes['sidebar_primary'] = "$prefix-$sp-$g";
$classes['sidebar_secondary'] = "$prefix-$ss-$g";
break;
case 'ss_c':
$c = $g - $sp;
$classes['content'] = "$prefix-$c-$g uk-push-$sp-$g";
$classes['sidebar_secondary'] = "$prefix-$sp-$g uk-pull-$c-$g";
break;
case 'sp_ss_c':
$c = $g - ( $sp + $ss );
$push_content = $sp + $ss;
$classes['content'] = "$prefix-$c-$g uk-push-$push_content-$g";
$classes['sidebar_primary'] = "$prefix-$sp-$g uk-pull-$c-$g";
$classes['sidebar_secondary'] = "$prefix-$ss-$g uk-pull-$c-$g";
break;
case 'sp_c_ss':
$c = $g - ( $sp + $ss );
$classes['content'] = "$prefix-$c-$g uk-push-$sp-$g";
$classes['sidebar_primary'] = "$prefix-$sp-$g uk-pull-$c-$g";
$classes['sidebar_secondary'] = "$prefix-$ss-$g";
break;
}
}
/**
* Filter the layout class.
*
* The dynamic portion of the hook name refers to the searched layout section ID.
*
* @since 1.0.0
*
* @param string $layout The layout class.
*/
return apply_filters( "beans_layout_class_$id", beans_get( $id, $classes ) );
}