JiveDig
5/10/2013 - 7:26 PM

Use post_class (post class) to break post into columns Last example shows how to conditionally use post class, for specific templates or pag

Use post_class (post class) to break post into columns Last example shows how to conditionally use post class, for specific templates or pages

/**
 * Breaks the posts into 4 columns
 * @link http://www.billerickson.net/code/grid-loop-using-post-class
 */
add_filter( 'post_class', 'tsm_archive_post_class' );
function tsm_archive_post_class( $classes ) {
	global $wp_query; 
	// Keeps columns out of secondary loops ie: Genesis Featured Post widgets
	if( ! $wp_query->is_main_query() ) {
		return $classes;
	}
 	$classes[] = 'one-fourth';
	if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % 4 )
		$classes[] = 'first';
	return $classes;
}


/**
 * Breaks the posts into 3 columns
 * @link http://www.billerickson.net/code/grid-loop-using-post-class
 */
add_filter( 'post_class', 'tsm_archive_post_class' );
function tsm_archive_post_class( $classes ) {
	global $wp_query;
	// Keeps columns out of secondary loops ie: Genesis Featured Post widgets
	if( ! $wp_query->is_main_query() ) {
		return $classes;
	}
	$classes[] = 'one-third';
	if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % 3 )
		$classes[] = 'first';
	return $classes;
}

/**
 * Breaks the posts into 2 columns
 * @link http://www.billerickson.net/code/grid-loop-using-post-class
 */
add_filter( 'post_class', 'tsm_archive_post_class' );
function tsm_archive_post_class( $classes ) {
	global $wp_query; 
	// Keeps columns out of secondary loops ie: Genesis Featured Post widgets
	if( ! $wp_query->is_main_query() ) {
		return $classes;
	}
	$classes[] = 'one-half';
	if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % 2 )
		$classes[] = 'first';
	return $classes;
}

// Set the number of posts per page
add_filter( 'pre_get_posts', 'be_archive_query' );
// @link http://www.billerickson.net/customize-the-wordpress-query/
function be_archive_query( $query ) {
	if( $query->is_main_query() && $query->is_archive() ) {
		$query->set( 'posts_per_page', 12 );
	}
}

// OR
// If you don't want the change to affect backend

// Set the number of posts per page
// @link http://www.billerickson.net/customize-the-wordpress-query/
add_filter( 'pre_get_posts', 'mwm_resource_affiliate_archive_query' );
function mwm_resource_affiliate_archive_query( $query ) {
	if ( ! is_admin() AND ( is_post_type_archive('resource') OR is_post_type_archive('affiliate') ) ) {
		$query->set( 'posts_per_page', 15 );
	}
}