Skip to content

Instantly share code, notes, and snippets.

@cdils
Forked from billerickson/grid-loop.php
Last active April 25, 2018 16:08
Show Gist options
  • Save cdils/4684423 to your computer and use it in GitHub Desktop.
Save cdils/4684423 to your computer and use it in GitHub Desktop.
Use this grid loop in a custom page template to show page content, followed by a loop through a custom post type.
<?php
/**
* Template Name: Testimonial Archives
* Description: Used as a page template to show page contents, followed by a loop through a CPT archive
*/
remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop
add_action( 'genesis_loop', 'custom_do_grid_loop' ); // Add custom loop
function custom_do_grid_loop() {
// Intro Text (from page content)
echo '<div class="page hentry entry">';
echo '<h1 class="entry-title">'. get_the_title() .'</h1>';
echo '<div class="entry-content">' . get_the_content() ;
$args = array(
'post_type' => 'testimonials', // enter your custom post type
'posts_per_page'=> '12', // overrides posts per page in theme settings
);
$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 '<h4>'.genesis_get_custom_field( '_cd_client_name' ).'</h4>'; //retrieving a custom field from the post
echo '<strong>' . get_the_title() . '</strong>';
echo the_post_thumbnail( 'thumbnail', array('class' => 'alignleft') );
echo '<blockquote>' . get_the_content() . '</blockquote>';
echo '</div>';
endwhile;
echo '</div>';
endif;
// Outro Text (hard coded)
echo '<div class="call-to-action">This is my call to action text. <a href"">Contact Me</a></div>';
echo '</div><!-- end .entry-content -->';
echo '</div><!-- end .page .hentry .entry -->';
}
/** Remove Post Info */
remove_action('genesis_before_post_content','genesis_post_info');
remove_action('genesis_after_post_content','genesis_post_meta');
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment