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

columns

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

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

Let's Talk