Skip to content

Instantly share code, notes, and snippets.

@braddalton
Last active May 30, 2022 12:45
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 braddalton/5aa7a5e97c81e657340d to your computer and use it in GitHub Desktop.
Save braddalton/5aa7a5e97c81e657340d to your computer and use it in GitHub Desktop.
add_action ( 'genesis_entry_footer', 'popular_posts_after_content' );
function popular_posts_after_content() {
if ( is_singular('post') ) {
get_template_part( 'wpsites' );
}}
.after-entry {
background-color: #f5f5f5;
margin: 25px 0px;
margin: 2.5rem 0rem;
padding: 40px;
padding: 4rem;
}
.after-entry li {
margin-bottom: 6px;
margin-bottom: 0.6rem;
}
<?php
/**
* @author Brad Dalton
* @example http://wpsites.net/wordpress-tips/fetch-display-a-list-of-popular-posts-by-comment-count/
* @copyright 2014 WP Sites
*/
// Your Custom Query
$sticky = get_option( 'sticky_posts' );
$args = array(
'orderby' => 'comment_count',
'posts_per_page' => 3,
'post__not_in' => $sticky
);
$popular_posts = new WP_Query( $args );
// Your Custom Loop
if ( $popular_posts->have_posts() ) {
echo '<div class="after-entry"><ul>';
while ( $popular_posts->have_posts() ) {
$popular_posts->the_post();
echo '<li><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . get_the_title() . '</a></li>';
}
echo '</ul></div>';
} else {
echo '<div class="after-entry">No posts found for this query.</div>';
}
wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment