Skip to content

Instantly share code, notes, and snippets.

@billerickson
Forked from anonymous/gist:8bd60d3273ca85cffa27
Last active May 17, 2020 06:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save billerickson/67cf0c77a74f409da652 to your computer and use it in GitHub Desktop.
Save billerickson/67cf0c77a74f409da652 to your computer and use it in GitHub Desktop.
<?php
/* Template Name: Fells */
/**
* My Custom Loop
*
*/
function be_custom_loop() {
$tags = wp_get_post_tags( get_the_ID() );
if( ! $tags )
return;
$tags = wp_list_pluck( $tags, 'term_id' );
$args = array(
'tag__in' => $tags,
'post__not_in' => array( get_the_ID() ),
'posts_per_page' => 5,
'ignore_sticky_posts' => true,
);
$loop = new WP_Query( $args );
if( $loop->have_posts() ):
echo '<h3>Related Posts</h3>';
while( $loop->have_posts() ): $loop->the_post();
echo '<p><a href="' . get_permalink() . '" rel="bookmark" title="' . the_title_attribute( array( 'echo' => false ) ) . '">' . get_the_title() . '</a></p>';
endwhile;
endif;
wp_reset_postdata();
}
add_action( 'genesis_loop', 'be_custom_loop' );
remove_action( 'genesis_loop', 'genesis_do_loop' );
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment