Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active August 25, 2017 16:37
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 billerickson/c8e47e61fff3fc0d8cab61001ace6d37 to your computer and use it in GitHub Desktop.
Save billerickson/c8e47e61fff3fc0d8cab61001ace6d37 to your computer and use it in GitHub Desktop.
<?php
/**
* Column Classes
*
* Adds "-first" classes when appropriate for clearing float
* @see /assets/scss/partials/layout.scss
*
* @param array $classes, bootstrap-style classes, ex: array( 'col-lg-4', 'col-md-6' )
* @param int $current, current post in loop
* @param bool $join, whether to join classes (return string) or return array
* @return array/string $classes
*/
function ea_column_class( $classes = array(), $current = false, $join = true ) {
if( false === $current )
return $classes;
$columns = array( 2, 3, 4, 6 );
foreach( $columns as $column ) {
if( 0 == $current % $column ) {
$col = 12 / $column;
foreach( $classes as $class ) {
if( false != strstr( $class, (string) $col ) && false == strstr( $class, '12' ) ) {
$classes[] = str_replace( $col, 'first', $class );
}
}
}
}
if( $join ) {
return join( ' ', $classes );
} else {
return $classes;
}
}
@include media(">=tablet", "<medium") {
.col-sm-first {
clear: both;
}
}
@include media(">=medium", "<large") {
.col-md-first {
clear: both;
}
}
@include media(">=large") {
.col-lg-first {
clear: both;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment