Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.