Get Column Classes

This function lets you automatically generate the necessary Column Classes when looping through a custom query.

<?php
/**
* Column Classes
*
* @param int $columns, how many columns content should be broken into
* @param int $count, the current post in the loop (starts at 0)
* @param int $extra_classes, any additional classes to add on all posts
* @return string $classes
*
* @author Bill Erickson
* @link http://www.billerickson.net/code/get-column-classes/
*/
function be_column_classes( $columns = 2, $count = 0, $extra_classes = '' ) {
$column_classes = array( '', '', 'one-half', 'one-third', 'one-fourth', 'one-fifth', 'one-sixth' );
$output = $column_classes[$columns];
if( 0 == $count || 0 == $count % $columns )
$output .= ' first';
if( $extra_classes )
$output .= ' ' . $extra_classes;
return $output;
}
view raw functions.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk