Grid Loop with Features/Teasers

<?php
add_filter( 'post_class', 'be_archive_post_classes' );
/**
* Archive Post Classes
*
* @param array $classes
* @return array
*/
function be_archive_post_classes( $classes ) {
$features = 2;
// Number of teasers is what's left over
$columns_of_teasers = 2;
global $wp_query;
if( $wp_query->query_vars['paged'] == 0 && $wp_query->current_post < $features )
$classes[] = 'feature';
else {
$classes[] = 'teaser';
if( 0 == $wp_query->current_post || 0 == $wp_query->current_post % $columns_of_teasers )
$classes[] = 'left';
else
$classes[] = 'right';
}
$page = $wp_query->query_vars['paged'] ? $wp_query->query_vars['paged'] : 1;
// Adds a class of 'last' to the last teaser
if( ( ( $wp_query->query_vars['posts_per_page'] - 1 ) == $wp_query->current_post) || ( $wp_query->query_vars['posts_per_page'] * ( $page - 1 ) + ( $wp_query->current_post + 1 ) == $wp_query->found_posts ) )
$classes[] = 'last';
return $classes;
}
add_filter( 'genesis_post_meta', 'be_archive_post_meta' );
/**
* Archive Post Meta
* Example of using the post class to customize just teasers
*/
function be_archive_post_meta( $post_meta ) {
if( in_array( 'teaser', get_post_class() ) )
$post_meta = '[post_tags before="Tags: "]';
return $post_meta;
}
view raw archive.php hosted with ❤ by GitHub

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