WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Jan 08 2013

Genesis Grid Loop in Genesis 1.9

Some people may be experiencing some issues with the Genesis Grid Loop in Genesis 1.9 (and rightly so).

[php]
if ( function_exists( 'genesis_grid_loop' ) ) {
genesis_grid_loop(
array(
'features' => 0,
'feature_image_size' => 0,
'feature_image_class' => 'alignright post-image',
'feature_content_limit' => 0,
'grid_image_size' => 'thumbnail',
'grid_image_class' => 'alignleft',
'grid_content_limit' => 250,
'more' => __( '[Read more...]', 'child-domain' ),
'posts_per_page' => 25,
/** Remove categories from loop */
'category__not_in' => array( 1, 2, 3, )
)
);
} else {
genesis_standard_loop();
}
[/php]

However, with Genesis 1.9, this will no longer work. Instead you must modify the query as you should via pre_get_posts hook. Bill Erickson has a great tutorial on how to do customize the WordPress Query, which I will also re-iterate here.

Custom Grid Loop Conditional

First, I love the Grid Loop setup that Gary and Bill did here. However, both Gary and Bill admit that there are other better options than using the genesis_grid_loop() such as Bill's Better, Easier Grid Loop.

However, some sites are just not worth re-doing. So in the meantime a fix is necessary. So here it is. Personally, I would use the function child_is_doing_grid_loop() from the Advanced Grid Loop. This will be the function where you declare all the places that you want the Grid Loop to appear using the WordPress Conditionals. This will keep your code organized.

<?php
/**
* Possibly amend the loop.
*
* Specify the conditions under which the grid loop should be used.
*
* @author Bill Erickson
* @author Gary Jones
* @author Travis Smith
* @link http://code.garyjones.co.uk/genesis-grid-loop-advanced/
* @link http://wpsmith.net/2013/genesis/genesis-grid-loop-in-genesis-1-9/
*
* @return boolean Return true of doing the grid loop, false if not.
*/
function wps_is_doing_grid_loop() {
// Amend this conditional to pick where this grid looping occurs.
// This says to use the grid loop everywhere except single posts,
// single pages and single attachments.
return ( ! is_singular() );
}
view raw wps_is_doing_grid_loop.php hosted with ❤ by GitHub

Modify the WordPress Query Correctly

Then you need to modify the WordPress Query via pre_get_posts hook. Here's how you can modify the query to exclude a category.

<?php
add_action( 'pre_get_posts', 'wps_exclude_cat_in_grid' );
/**
* Exclude Category from Grid
*
* @author Bill Erickson
* @author Travis Smith
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @link http://wpsmith.net/2013/genesis/genesis-grid-loop-in-genesis-1-9/
* @param object $query WP Query data
*
*/
function wps_exclude_cat_in_grid( $query ) {
if( $query->is_main_query() && wps_is_doing_grid_loop() ) {
$query->set( 'cat', '-1,-2' );
}
}
view raw wps_exclude_cat_in_grid.php hosted with ❤ by GitHub

Here's how you can modify the query to limit the query to a category.

<?php
add_action( 'pre_get_posts', 'wps_include_cat_in_grid' );
/**
* Limit Query to one Category
*
* @author Bill Erickson
* @author Travis Smith
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @link http://wpsmith.net/2013/genesis/genesis-grid-loop-in-genesis-1-9/
* @param object $query WP Query data
*
*/
function wps_include_cat_in_grid( $query ) {
if( $query->is_main_query() && wps_is_doing_grid_loop() ) {
$query->set( 'cat', '4' );
}
}
view raw wps_include_cat_in_grid.php hosted with ❤ by GitHub

Here's how you can modify the query to change the posts_per_page.

<?php
add_action( 'pre_get_posts', 'wps_change_posts_per_page_in_grid' );
/**
* Change Posts Per Page
*
* @author Bill Erickson
* @author Travis Smith
* @link http://www.billerickson.net/customize-the-wordpress-query/
* @link http://wpsmith.net/2013/genesis/genesis-grid-loop-in-genesis-1-9/
* @param object $query WP Query data
*
*/
function wps_change_posts_per_page_in_grid( $query ) {
global $wp_the_query;
if( $query->is_main_query() && wps_is_doing_grid_loop() ) {
$query->set( 'posts_per_page', '15' );
}
}
view raw wps_change_posts_per_page_in_grid.php hosted with ❤ by GitHub

Please note that all of this code belongs in functions.php or some other custom file. I personally recommend a custom query.php or grid.php file to keep your code clean.

So back in your template file, you can change the original loop function to:
[php]
if ( function_exists( 'genesis_grid_loop' ) ) {
genesis_grid_loop(
array(
'features' => 0,
'feature_image_size' => 0,
'feature_image_class' => 'alignright post-image',
'feature_content_limit' => 0,
'grid_image_size' => 'thumbnail',
'grid_image_class' => 'alignleft',
'grid_content_limit' => 250,
'more' => __( '[Read more...]', 'child-domain' ),
)
);
} else {
genesis_standard_loop();
}
[/php]
These are the necessary components for displaying the loop, which is modified via pre_get_posts now.

Written by Travis Smith · Categorized: Genesis, Genesis Grid Loop

Jan 07 2013

Create Genesis Constants Based on Theme

In my child themes, this little function that I wrote based on the new wp_get_theme() function (Codex, WP Ticket). Previously, I had to create style.css with all the data and then had to do the same thing in functions.php (or my child init.php). So to save 30 seconds or so, I have no fully automated this entirely, so everything in style.css matters. Everything!

Let's step through the style.css header.

/*
Theme Name: Genesis Child
Theme URI: http://wpsmith.net/
Description: Default Genesis Child Theme.
Author: Travis Smith
Author URI: http://wpsmith.net/
Version: 1.0.0
Text Domain: genesis-child
Tags: black, white, red, one-column, two-columns, three-columns, left-sidebar, right-sidebar, fixed-width, custom-background, custom-header, custom-menu, editor-style, full-width-template, sticky-post, theme-options, threaded-comments, translation-ready
Template: genesis
Template Version: 1.9.0
License: GNU General Public License v3.0 (or later)
License URI: http://opensource.org/licenses/gpl-license.php
*/
view raw style.css hosted with ❤ by GitHub

Obviously, Template and Template version should be set for every child theme.

So Theme Name will determine CHILD_THEME_NAME, which will automatically appear in the Genesis Footer connected with the Theme URI, which is set as CHILD_THEME_URL. WordPress pulls in the Description on the Appearance > Themes page. I have an admin script that I make better use of Author and Author URI besides the basic WordPress listing them in Appearance > Themes (as it also uses Tags). It places it in the footer stating, "Thank you for creating with WordPress & CHILD_THEME_NAME designed by CHILD_DEVELOPER" linked with CHILD_DEVELOPER_URL.

What's even more awesome is that Genesis 1.9 makes use of CHILD_THEME_VERSION if it is set in enqueuing the style. So, it's important, but I also use it elsewhere. Then the even more awesome thing is Text Domain! Text Domain sets two constants: CHILD_DOMAIN (localization) and CHILD_THEME_SETTINGS (admin page). So if Text Domain is set as 'genesis-child' then the CHILD_DOMAIN will be 'genesis-child' and the CHILD_THEME_SETTINGS will be 'genesis-child-settings'.

Now, I don't have to think a single bit for my theme constants. I just use this function in all child themes I create.

<?php
add_action( 'genesis_init', 'gs_constants', 15 );
/**
* This function defines the Genesis Child theme constants
*
* Data Constants: CHILD_SETTINGS_FIELD, CHILD_DOMAIN, CHILD_THEME_VERSION
* CHILD_THEME_NAME, CHILD_THEME_URL, CHILD_DEVELOPER, CHILD_DEVELOPER_URL
* Directories: CHILD_LIB_DIR, CHILD_IMAGES_DIR, CHILD_ADMIN_DIR, CHILD_JS_DIR, CHILD_CSS_DIR
* URLs: CHILD_LIB, CHILD_IMAGES, CHILD_ADMIN, CHILD_JS, CHILD_CSS
*
* @since 1.1.0
*/
function gs_constants() {
$theme = wp_get_theme();
// Child theme (Change but do not remove)
/** @type constant Child Theme Options/Settings. */
define( 'CHILD_SETTINGS_FIELD', $theme->get('TextDomain') . '-settings' );
/** @type constant Text Domain. */
define( 'CHILD_DOMAIN', $theme->get('TextDomain') );
/** @type constant Child Theme Version. */
define( 'CHILD_THEME_VERSION', $theme->Version );
/** @type constant Child Theme Name, used in footer. */
define( 'CHILD_THEME_NAME', $theme->Name );
/** @type constant Child Theme URL, used in footer. */
define( 'CHILD_THEME_URL', $theme->get('ThemeURI') );
// Developer Information, see lib/admin/admin-functions.php
/** @type constant Child Theme Developer, used in footer. */
define( 'CHILD_DEVELOPER', $theme->Author );
/** @type constant Child Theme Developer URL, used in footer. */
define( 'CHILD_DEVELOPER_URL', $theme->{'Author URI'} );
// Define Directory Location Constants
/** @type constant Child Theme Library/Includes URL Location. */
define( 'CHILD_LIB_DIR', CHILD_DIR . '/lib' );
/** @type constant Child Theme Images URL Location. */
define( 'CHILD_IMAGES_DIR', CHILD_DIR . '/images' );
/** @type constant Child Theme Admin URL Location. */
define( 'CHILD_ADMIN_DIR', CHILD_LIB_DIR . '/admin' );
/** @type constant Child Theme JS URL Location. */
define( 'CHILD_JS_DIR', CHILD_DIR .'/js' );
/** @type constant Child Theme JS URL Location. */
define( 'CHILD_CSS_DIR', CHILD_DIR .'/css' );
// Define URL Location Constants
/** @type constant Child Theme Library/Includes URL Location. */
define( 'CHILD_LIB', CHILD_URL . '/lib' );
/** @type constant Child Theme Images URL Location. */
define( 'CHILD_IMAGES', CHILD_URL . '/images' );
/** @type constant Child Theme Admin URL Location. */
define( 'CHILD_ADMIN', CHILD_LIB . '/admin' );
/** @type constant Child Theme JS URL Location. */
define( 'CHILD_JS', CHILD_URL .'/js' );
/** @type constant Child Theme JS URL Location. */
define( 'CHILD_CSS', CHILD_URL .'/css' );
}
view raw gs_constants.php hosted with ❤ by GitHub

Written by Travis Smith · Categorized: WordPress

Jan 04 2013

Add private/draft/future/pending pages to parent dropdown in page attributes and Quick Edit

<?php
add_filter( 'page_attributes_dropdown_pages_args', 'wps_dropdown_pages_args_add_parents' );
add_filter( 'quick_edit_dropdown_pages_args', 'wps_dropdown_pages_args_add_parents' );
/**
* Add private/draft/future/pending pages to parent dropdown.
*/
function wps_dropdown_pages_args_add_parents( $dropdown_args, $post = NULL ) {
$dropdown_args['post_status'] = array( 'publish', 'draft', 'pending', 'future', 'private', );
return $dropdown_args;
}
view raw wps_dropdown_pages_args_add_parents.php hosted with ❤ by GitHub

Written by Travis Smith · Categorized: WordPress

Jan 03 2013

Disable AutoSave on Add New Post Admin Page

Disabling revisions won't stop WordPress from creating the initial draft version of a custom post type. So I used this snippet to accomplish this as well.

<?php
add_action( 'admin_enqueue_scripts', 'wps_cpt_admin_enqueue_scripts' );
/**
* Disable initial autosave/autodraft
*/
function wps_cpt_admin_enqueue_scripts() {
if ( 'cpt' == get_post_type() )
wp_dequeue_script( 'autosave' );
}
view raw wps_cpt_admin_enqueue_scripts.php hosted with ❤ by GitHub

Written by Travis Smith · Categorized: Custom Post Types

Dec 28 2012

Genesis Child Theme Code Audit

Calling all Genesis developers! Through January 2nd, I am offering a basic initial audit of up to 4 Genesis child themes for $50 and only $50!

Get it Now!

You may be thinking, "Why should I audit my theme if it is selling already so well?" Or, "My theme is on the Genesis Marketplace and doesn't need to be audited." Or, "I purchased this from the Genesis Marketplace, so the theme has already been audited." Or, "I developed this theme for a client who won't know." Or, "I had this theme developed by another Genesis developer, and I am just not sure about it."

First, themes on the Genesis Marketplace have not necessarily been audited. Genesis Marketplace themes are developer dependent. While StudioPress recommended these themes be audited by myself or Gary Jones or another developer, the submitting developer may or may not have done this because until now, audits were expensive. Thus, the theme may or may not be written to WordPress standards and/or best practices.

Second, themes audited almost always reveal something, which will lead to easier maintenance, lower support costs, code confidence, and happier customers! Customers always find out how good or bad the code is/was that was written. The theme/site may come into conflict with a plugin that they want to use. The theme/site may have issues with the Genesis/WordPress upgrade cycle. Whatever the case, they either return to you, try to do it themselves, or hire another Genesis developer. Even themes/sites I've built six months ago give me shivers when I go back and work on them. I've worked on themes that were originally developed by many Genesis developers and surely there have been Genesis developers who have worked on sites that I originally created. If, however, I had the theme/site audited then I would have most definitely produced a better product and had more confidence in my code.

Get the Audit Today

Written by Travis Smith · Categorized: Genesis

  • « Previous Page
  • 1
  • …
  • 10
  • 11
  • 12
  • 13
  • 14
  • …
  • 60
  • Next Page »

Need Help?

Please let us know how we can help you!

Get Help

Recommendations

Genesis WordPress Framework
Sucuri Security
Gravity Forms
GetSoliloquy
Get Envira
Scribe SEO
BackupBuddy
WordPress Video User Manuals

Recent Posts

  • Solving WordPress 5XX Server Errors on SiteGround
  • Hiding an User in the WordPress Admin
  • Custom Rewrite Rules for Custom Post Types and Taxonomies
  • WordPress JavaScript Manager Native Functions
  • Causes of WordPress Site Performance Slowdown

About Travis

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in