-
-
Save billerickson/67cf0c77a74f409da652 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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