Skip to content

Instantly share code, notes, and snippets.

@braddalton braddalton/functions.php Secret
Last active Sep 13, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.