Last active
December 10, 2015 20:38
-
-
Save wpsmith/4489534 to your computer and use it in GitHub Desktop.
Customizing the WordPress Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment