Skip to content
billerickson edited this page Sep 21, 2012 · 17 revisions

The Genesis Grid plugin was design to allow users of the Genesis theme to easily display their posts in a grid format.

"Features" are full-width posts at the top of the listing. "Teasers" are the posts broken into columns. You can set the number of Features and Teasers for both the homepage and inner pages, and how many columns the teasers are broken into.

You can also specify the image sizes used for Features and Teasers. I recommend setting Features for Large, and Teasers for Medium. Then go to Settings > Reading and set the dimensions of those images as needed. If you have already uploaded images, use the Regenerate Thumbnails plugin to rebuild the thumbnails at these dimensions. If images aren't showing up, make sure you have "Include featured images" checked in Genesis > Theme Settings > Content Archives

Finally, you can specify where the grid loop is used by checking Home, Category Archives, Tag Archives, and/or Search Results. See the Developers section for more fine-grained control.

Why use this plugin?

One of the features of Genesis is a grid loop, so why use a plugin for this?

The built-in grid loop creates a new WordPress query, so it should only be used for secondary queries, not the main post listing of the page. A good use of it might be, on your Services page, listing three projects from your portfolio.

Why shouldn't it be used for the main query (ex: blog post listing)?

  1. You will get 404 errors (Page Not Found) if you change the number of posts displayed from the default in Settings > Reading, or if you add any additional query arguments to it, like excluding posts from a certain category. More information.
  2. Every time you use genesis_grid_loop(), it does 4 extra queries to your database, slowing down your site. There's no reason to do this if WordPress has already loaded all the posts you need.
  3. The grid loop is more difficult to customize than using the main loop. The main loop includes all the hooks and filters you know and love.

This plugin is for displaying your standard archive pages (home, categories, search results...) in a grid loop.

For Developers

You can use the genesis_grid_loop_section filter to customize exactly where the grid loop is used. If you wanted to use the grid loop on the archive page for your 'portfolio' post type, add this to your theme's functions.php file:

<?php
/**
 * Grid Loop on Portfolio archive
 *
 * @author Bill Erickson
 * @link https://github.com/billerickson/Genesis-Grid/wiki/Home
 *
 * @param bool $grid, whether to use grid loop
 * @param object $query, the WP Query
 * @return bool
 */
function be_grid_loop_on_portfolio( $grid, $query ) {
	if( is_post_type_archive( 'portfolio' ) )
		$grid = true;

	return $grid;
}
add_filter( 'genesis_grid_loop_section', 'be_grid_loop_on_portfolio', 10, 2 );

You can use the genesis_grid_loop_args filter to customize the grid args, set in the Theme Settings page ( Genesis > Grid Loop ). Let's say you set your Grid Loop to have 1 Feature on Front, but on your blog's homepage you want to use 2 (all other places, like category and tag archives, you want it to stay 1). You could use this in your theme's functions.php file:

<?php
/**
 * Homepage Grid Args
 *
 * @author Bill Erickson
 * @link https://github.com/billerickson/Genesis-Grid/wiki/Home
 *
 * @param array $args, grid arguments
 * @param object $query, the WP Query
 * @return array $args
 */
function be_homepage_grid_args( $args, $query ) {
	if( is_home() )
		$args['features_on_front'] = 2;
	
	return $args;
}
add_filter( 'genesis_grid_loop_args', 'be_homepage_grid_args', 10, 2 );

If you want to see if you're currently in a grid loop, you can include this in your theme: $grid = apply_filters( 'is_genesis_grid_loop', false ); If you are in a grid loop, it will return an array of all the grid args. If you aren't in a grid loop, it will return false.

You can also check the post classes to see if you're in a feature or a teaser.

<?php

if( in_array( 'feature', get_post_class() ) )
	// do something only on features
Clone this wiki locally