Skip to content

Instantly share code, notes, and snippets.

@varickdesign
Created January 15, 2013 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save varickdesign/4542358 to your computer and use it in GitHub Desktop.
Save varickdesign/4542358 to your computer and use it in GitHub Desktop.
Code That Worked To Pull in Pages in WP using Grid Loop under Genesis 1.8. Can see it working here http://tinyurl.com/an2ny5j
add_action( 'genesis_before_loop', 'child_maybe_do_grid_loop' );
function child_maybe_do_grid_loop() {
// Amend this conditional to pick where this grid looping occurs
if ( is_page('2') ) {
remove_action('genesis_before_post_content', 'genesis_post_info');
// Use the prepared grid loop
add_action( 'genesis_loop', 'staff_do_grid_loop' );
// Add some extra post classes to the grid loop so we can style the columns
/* add_filter( 'genesis_grid_loop_post_class', 'child_grid_loop_post_class' );*/
}
if ( is_page('solutions') ) {
remove_action('genesis_before_post_content', 'genesis_post_info');
// Use the prepared grid loop
add_action( 'genesis_loop', 'solutions_do_grid_loop' );
// Add some extra post classes to the grid loop so we can style the columns
/* add_filter( 'genesis_grid_loop_post_class', 'child_grid_loop_post_class' );*/
}
if ( is_page('7') ) {
remove_action('genesis_before_post_content', 'genesis_post_info');
// Use the prepared grid loop
add_action( 'genesis_loop', 'capabilities_do_grid_loop' );
// Add some extra post classes to the grid loop so we can style the columns
/* add_filter( 'genesis_grid_loop_post_class', 'child_grid_loop_post_class' ); */
}
}
function staff_do_grid_loop() {
global $query_string, $paged;
// Ensure the arguments for the normal query for the page are carried forwards
// If you're using a Page to query the posts (e.g. with the Blog template), comment out the next line.
wp_parse_str( $query_string, $query_args );
$query_args = array(
'post_type' => 'page',
'meta_key' => 'staff',
'orderby' => 'menu_order',
'order' => 'ASC',
);
// Create an array of arguments for the loop - can be grid-specific, or
// normal query_posts() arguments to alter the loop
$grid_args = array(
'features' => 0,
'feature_image_size' => 0,
'feature_image_class' => 'alignleft post-image',
'feature_content_limit' => 0,
'grid_image_size' => 'Bio-Thumbnails',
'grid_image_class' => 'alignleft post-image',
'grid_content_limit' => 0,
'more' =>'',
'posts_per_page' => 6,
);
// Make sure the first page has a balanced grid
if ( 0 == $paged )
// If first page, add number of features to grid posts, so balance is maintained
$grid_args['posts_per_page'] += $grid_args['features'];
else
// Keep the offset maintained from our page 1 adjustment
$grid_args['offset'] = ( $paged - 1 ) * $grid_args['posts_per_page'] + $grid_args['features'];
// Merge the standard query for this page, and our preferred loop arguments
genesis_grid_loop( array_merge( (array) $query_args, $grid_args ) );
}
function solutions_do_grid_loop() {
global $query_string, $paged;
// Ensure the arguments for the normal query for the page are carried forwards
// If you're using a Page to query the posts (e.g. with the Blog template), comment out the next line.
wp_parse_str( $query_string, $query_args );
$query_args = array(
'post_type' => 'page',
'meta_key' => 'solutions',
'orderby' => 'menu_order',
'order' => 'ASC'
);
// Create an array of arguments for the loop - can be grid-specific, or
// normal query_posts() arguments to alter the loop
$grid_args = array(
'features' => 0,
'feature_image_size' => 0,
'feature_image_class' => 'alignleft post-image',
'feature_content_limit' => 0,
'grid_image_size' => 'Bio-Thumbnails',
'grid_image_class' => 'alignleft post-image',
'grid_content_limit' => 0,
'more' =>'',
'posts_per_page' => 6,
);
// Make sure the first page has a balanced grid
if ( 0 == $paged )
// If first page, add number of features to grid posts, so balance is maintained
$grid_args['posts_per_page'] += $grid_args['features'];
else
// Keep the offset maintained from our page 1 adjustment
$grid_args['offset'] = ( $paged - 1 ) * $grid_args['posts_per_page'] + $grid_args['features'];
// Merge the standard query for this page, and our preferred loop arguments
genesis_grid_loop( array_merge( (array) $query_args, $grid_args ) );
}
function capabilities_do_grid_loop() {
global $query_string, $paged;
// Ensure the arguments for the normal query for the page are carried forwards
// If you're using a Page to query the posts (e.g. with the Blog template), comment out the next line.
wp_parse_str( $query_string, $query_args );
$query_args = array(
'post_type' => 'page',
'meta_key' => 'cpi_pages_cat',
'meta_value' => 'capabilities',
'orderby' => 'menu_order',
'order' => 'ASC'
);
// Create an array of arguments for the loop - can be grid-specific, or
// normal query_posts() arguments to alter the loop
$grid_args = array(
'features' => 0,
'feature_image_size' => 0,
'feature_image_class' => 'alignleft post-image',
'feature_content_limit' => 0,
'grid_image_size' => 'Bio-Thumbnails',
'grid_image_class' => 'alignleft post-image',
'grid_content_limit' => 0,
'more' =>'',
'posts_per_page' => 6,
);
// Make sure the first page has a balanced grid
if ( 0 == $paged )
// If first page, add number of features to grid posts, so balance is maintained
$grid_args['posts_per_page'] += $grid_args['features'];
else
// Keep the offset maintained from our page 1 adjustment
$grid_args['offset'] = ( $paged - 1 ) * $grid_args['posts_per_page'] + $grid_args['features'];
// Merge the standard query for this page, and our preferred loop arguments
genesis_grid_loop( array_merge( (array) $query_args, $grid_args ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment