Skip to content

Instantly share code, notes, and snippets.

@billerickson
Forked from varickdesign/Not Working Grid Loop
Last active December 11, 2015 04:49
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save billerickson/4548000 to your computer and use it in GitHub Desktop.
<?php
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() {
$args = array(
'post_type' => 'page',
'meta_key' => 'staff',
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page',
);
$loop = new WP_Query( $args );
if( $loop->have_posts() ):
echo '<div class="grid-loop">';
while( $loop->have_posts() ): $loop->the_post(); global $post;
$classes = 0 == $loop->current_post || 0 == $loop->current_post % 2 ? 'one-half first' : 'one-half';
echo '<div class="' . $classes . '">';
echo '<h2><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
echo '<p>' . get_the_excerpt() . '</p>';
echo '</div>';
endwhile;
echo '</div>';
endif;
wp_reset_post_data();
}
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