Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created August 5, 2019 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/cbed55d31f697b0d9375ad8ff6b54b94 to your computer and use it in GitHub Desktop.
Save billerickson/cbed55d31f697b0d9375ad8ff6b54b94 to your computer and use it in GitHub Desktop.
<?php
/**
* Single
*
* @package EAStarter
* @author Bill Erickson
* @since 1.0.0
* @license GPL-2.0+
**/
/**
* Related Posts
*
*/
function ea_single_related_posts() {
$loop = new WP_Query( array(
'posts_per_page' => 3,
'post__not_in' => array( get_the_ID() ),
'category_name' => ea_first_term( 'category', 'slug' )
) );
if( $loop->have_posts() ):
echo '<section class="related-posts">';
echo '<header><h3>Related Posts</h3></header>';
while( $loop->have_posts() ): $loop->the_post();
get_template_part( 'partials/archive', 'related' );
endwhile;
echo '</section>';
endif;
wp_reset_postdata();
}
add_action( 'tha_entry_after', 'ea_single_related_posts', 5 );
// Build the page
require get_template_directory() . '/index.php';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment