Last active
May 30, 2022 12:45
-
-
Save braddalton/5aa7a5e97c81e657340d to your computer and use it in GitHub Desktop.
List Popular Posts By Comment Count http://wpsites.net/wordpress-tips/fetch-display-a-list-of-popular-posts-by-comment-count/
This file contains 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
add_action ( 'genesis_entry_footer', 'popular_posts_after_content' ); | |
function popular_posts_after_content() { | |
if ( is_singular('post') ) { | |
get_template_part( 'wpsites' ); | |
}} |
This file contains 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
.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; | |
} |
This file contains 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 | |
/** | |
* @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